mirror of https://github.com/apache/jclouds.git
Issue #830 vcloud-director: fix querying of VMs (and move instantiateVApp up to BaseVCloudDirectorClientLiveTest)
This commit is contained in:
parent
57235198d1
commit
214e25863b
|
@ -47,6 +47,7 @@ import com.google.common.collect.Sets;
|
|||
@XmlSeeAlso({
|
||||
QueryResultVAppTemplateRecord.class,
|
||||
QueryResultVAppRecord.class,
|
||||
QueryResultVMRecord.class,
|
||||
QueryResultDatastoreRecord.class,
|
||||
QueryResultCatalogRecord.class,
|
||||
QueryResultNetworkRecord.class}
|
||||
|
|
|
@ -30,13 +30,13 @@ import com.google.common.base.Objects;
|
|||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* Represents the results from a Datastore vCloud query as a record.
|
||||
* Represents the results from a VAppTemplate vCloud query as a record.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="QueryResultDatastoreRecordType" />
|
||||
* <complexType name="QueryResultVAppTemplateRecordType" />
|
||||
* </pre>
|
||||
*
|
||||
* @author grkvlt@apache.org
|
||||
* @author Aled Sage
|
||||
*/
|
||||
@XmlRootElement(name = "VAppTemplateRecord")
|
||||
@XmlType(name = "QueryResultVAppTemplateRecordType")
|
||||
|
@ -48,7 +48,7 @@ public class QueryResultVAppTemplateRecord extends QueryResultRecordType {
|
|||
|
||||
@Override
|
||||
public Builder<?> toBuilder() {
|
||||
return builder().fromQueryResultDatastoreRecord(this);
|
||||
return builder().fromQueryResultVappTemplateRecord(this);
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
|
@ -179,7 +179,7 @@ public class QueryResultVAppTemplateRecord extends QueryResultRecordType {
|
|||
return new QueryResultVAppTemplateRecord(this);
|
||||
}
|
||||
|
||||
public B fromQueryResultDatastoreRecord(QueryResultVAppTemplateRecord in) {
|
||||
public B fromQueryResultVappTemplateRecord(QueryResultVAppTemplateRecord in) {
|
||||
return fromQueryResultRecordType(in)
|
||||
.ownerName(in.getOwnerName())
|
||||
.catalogName(in.getCatalogName())
|
||||
|
|
|
@ -0,0 +1,417 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.vcloud.director.v1_5.domain.query;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* Represents the results from a VM vCloud query as a record.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="QueryResultVMRecordType" />
|
||||
* </pre>
|
||||
*
|
||||
* @author Aled Sage
|
||||
*/
|
||||
@XmlRootElement(name = "VMRecord")
|
||||
@XmlType(name = "QueryResultVMRecordType")
|
||||
public class QueryResultVMRecord extends QueryResultRecordType {
|
||||
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<?> toBuilder() {
|
||||
return builder().fromQueryResultVMRecord(this);
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
}
|
||||
|
||||
public static class Builder<B extends Builder<B>> extends QueryResultRecordType.Builder<B> {
|
||||
|
||||
private String name;
|
||||
private String containerName;
|
||||
private String container;
|
||||
private String vdc;
|
||||
private Boolean isVAppTemplate;
|
||||
private Boolean isDeleted;
|
||||
private String guestOs;
|
||||
private Integer numberOfCpus;
|
||||
private Integer memoryMB;
|
||||
private String status;
|
||||
private Boolean isBusy;
|
||||
private Boolean isDeployed;
|
||||
private Boolean isPublished;
|
||||
private Boolean catalogName;
|
||||
private Integer hardwareVersion;
|
||||
private Boolean isInMaintenanceMode;
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getName()
|
||||
*/
|
||||
public B name(String val) {
|
||||
this.name = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getContainerName()
|
||||
*/
|
||||
public B containerName(String val) {
|
||||
this.containerName = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getContainer()
|
||||
*/
|
||||
public B container(String val) {
|
||||
this.container = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getVdc()
|
||||
*/
|
||||
public B vdc(String val) {
|
||||
this.vdc = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#isVAppTemplate()
|
||||
*/
|
||||
public B isVAppTemplate(Boolean val) {
|
||||
this.isVAppTemplate = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#isDeleted()
|
||||
*/
|
||||
public B isDeleted(Boolean val) {
|
||||
this.isDeleted = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getGuestOs()
|
||||
*/
|
||||
public B guestOs(String val) {
|
||||
this.guestOs = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getNumberOfCpus()
|
||||
*/
|
||||
public B numberOfCpus(Integer val) {
|
||||
this.numberOfCpus = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getMemoryMB()
|
||||
*/
|
||||
public B memoryMB(Integer val) {
|
||||
this.memoryMB = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getStatus()
|
||||
*/
|
||||
public B status(String val) {
|
||||
this.status = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#isBusy()
|
||||
*/
|
||||
public B isBusy(Boolean val) {
|
||||
this.isBusy = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#isDeployed()
|
||||
*/
|
||||
public B isDeployed(Boolean val) {
|
||||
this.isDeployed = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#isPublished()
|
||||
*/
|
||||
public B isPublished(Boolean val) {
|
||||
this.isPublished = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#isCatalogName()
|
||||
*/
|
||||
public B catalogName(Boolean val) {
|
||||
this.catalogName = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#getHardwareVersion()
|
||||
*/
|
||||
public B hardwareVersion(Integer val) {
|
||||
this.hardwareVersion = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryResultVMRecord#isInMaintenanceMode()
|
||||
*/
|
||||
public B isInMaintenanceMode(Boolean val) {
|
||||
this.isInMaintenanceMode = val;
|
||||
return self();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryResultVMRecord build() {
|
||||
return new QueryResultVMRecord(this);
|
||||
}
|
||||
|
||||
public B fromQueryResultVMRecord(QueryResultVMRecord in) {
|
||||
return fromQueryResultRecordType(in)
|
||||
.name(in.getName())
|
||||
.containerName(in.getContainerName())
|
||||
.container(in.getContainer())
|
||||
.vdc(in.getVdc())
|
||||
.isVAppTemplate(in.isVAppTemplate())
|
||||
.isDeleted(in.isDeleted())
|
||||
.guestOs(in.getGuestOs())
|
||||
.numberOfCpus(in.getNumberOfCpus())
|
||||
.memoryMB(in.getMemoryMB())
|
||||
.status(in.getStatus())
|
||||
.isBusy(in.isBusy())
|
||||
.isDeployed(in.isDeployed())
|
||||
.isPublished(in.isPublished())
|
||||
.catalogName(in.isCatalogName())
|
||||
.hardwareVersion(in.getHardwareVersion())
|
||||
.isInMaintenanceMode(in.isInMaintenanceMode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
private String name;
|
||||
@XmlAttribute
|
||||
private String containerName;
|
||||
@XmlAttribute
|
||||
private String container;
|
||||
@XmlAttribute
|
||||
private String vdc;
|
||||
@XmlAttribute
|
||||
private Boolean isVAppTemplate;
|
||||
@XmlAttribute
|
||||
private Boolean isDeleted;
|
||||
@XmlAttribute
|
||||
private String guestOs;
|
||||
@XmlAttribute
|
||||
private Integer numberOfCpus;
|
||||
@XmlAttribute
|
||||
private Integer memoryMB;
|
||||
@XmlAttribute
|
||||
private String status;
|
||||
@XmlAttribute
|
||||
private Boolean isBusy;
|
||||
@XmlAttribute
|
||||
private Boolean isDeployed;
|
||||
@XmlAttribute
|
||||
private Boolean isPublished;
|
||||
@XmlAttribute
|
||||
private Boolean catalogName;
|
||||
@XmlAttribute
|
||||
private Integer hardwareVersion;
|
||||
@XmlAttribute
|
||||
private Boolean isInMaintenanceMode;
|
||||
|
||||
protected QueryResultVMRecord(Builder<?> builder) {
|
||||
super(builder);
|
||||
this.name = builder.name;
|
||||
this.containerName = builder.containerName;
|
||||
this.container = builder.container;
|
||||
this.vdc = builder.vdc;
|
||||
this.isVAppTemplate = builder.isVAppTemplate;
|
||||
this.isDeleted = builder.isDeleted;
|
||||
this.guestOs = builder.guestOs;
|
||||
this.numberOfCpus = builder.numberOfCpus;
|
||||
this.memoryMB = builder.memoryMB;
|
||||
this.status = builder.status;
|
||||
this.isBusy = builder.isBusy;
|
||||
this.isDeployed = builder.isDeployed;
|
||||
this.isPublished = builder.isPublished;
|
||||
this.catalogName = builder.catalogName;
|
||||
this.hardwareVersion = builder.hardwareVersion;
|
||||
this.isInMaintenanceMode = builder.isInMaintenanceMode;
|
||||
}
|
||||
|
||||
protected QueryResultVMRecord() {
|
||||
// for JAXB
|
||||
}
|
||||
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vapp name or Vapp template name
|
||||
*/
|
||||
public String getContainerName() {
|
||||
return containerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vapp or Vapp template
|
||||
*/
|
||||
public String getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* vDC reference or id
|
||||
*/
|
||||
public String getVdc() {
|
||||
return vdc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows whether the VM belongs to VApp or VAppTemplate
|
||||
*/
|
||||
public Boolean isVAppTemplate() {
|
||||
return isVAppTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows whether it is deleted
|
||||
*/
|
||||
public Boolean isDeleted() {
|
||||
return isDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Guest operating system
|
||||
*/
|
||||
public String getGuestOs() {
|
||||
return guestOs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of CPUs
|
||||
*/
|
||||
public Integer getNumberOfCpus() {
|
||||
return numberOfCpus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Memory in MB
|
||||
*/
|
||||
public Integer getMemoryMB() {
|
||||
return memoryMB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status
|
||||
*/
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows whether it is busy
|
||||
*/
|
||||
public Boolean isBusy() {
|
||||
return isBusy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows whether it is deployed
|
||||
*/
|
||||
public Boolean isDeployed() {
|
||||
return isDeployed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows whether it is in published catalog
|
||||
*/
|
||||
public Boolean isPublished() {
|
||||
return isPublished;
|
||||
}
|
||||
|
||||
/**
|
||||
* Catalog name
|
||||
*/
|
||||
public Boolean isCatalogName() {
|
||||
return catalogName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hardware version
|
||||
*/
|
||||
public Integer getHardwareVersion() {
|
||||
return hardwareVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows whether it is in maintenance mode
|
||||
*/
|
||||
public Boolean isInMaintenanceMode() {
|
||||
return isInMaintenanceMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
QueryResultVMRecord that = QueryResultVMRecord.class.cast(o);
|
||||
|
||||
return super.equals(that) && equal(name, that.name) && equal(containerName, that.containerName) && equal(container, that.container) && equal(vdc, that.vdc) && equal(isVAppTemplate, that.isVAppTemplate) && equal(isDeleted, that.isDeleted) && equal(guestOs, that.guestOs) && equal(numberOfCpus, that.numberOfCpus) && equal(memoryMB, that.memoryMB) && equal(status, that.status) && equal(isBusy, that.isBusy) && equal(isDeployed, that.isDeployed) && equal(isPublished, that.isPublished) && equal(catalogName, that.catalogName) && equal(hardwareVersion, that.hardwareVersion) && equal(isInMaintenanceMode, that.isInMaintenanceMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), name, containerName, container, vdc, isVAppTemplate, isDeleted, guestOs, numberOfCpus, memoryMB, status, isBusy, isDeployed, isPublished, catalogName, hardwareVersion, isInMaintenanceMode);
|
||||
}
|
||||
@Override
|
||||
public ToStringHelper string() {
|
||||
return super.string().add("name", name).add("containerName", containerName).add("container", container).add("vdc", vdc).add("isVAppTemplate", isVAppTemplate).add("isDeleted", isDeleted).add("guestOs", guestOs).add("numberOfCpus", numberOfCpus).add("memoryMB", memoryMB).add("status", status).add("isBusy", isBusy).add("isDeployed", isDeployed).add("isPublished", isPublished).add("catalogName", catalogName).add("hardwareVersion", hardwareVersion).add("isInMaintenanceMode", isInMaintenanceMode);
|
||||
}
|
||||
}
|
|
@ -19,26 +19,40 @@
|
|||
package org.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntityType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ResourceType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.UndeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vm;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntityType.Status;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests live behavior of {@link QueryClient}.
|
||||
*
|
||||
|
@ -53,12 +67,49 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
private QueryClient queryClient;
|
||||
private VAppTemplateClient vappTemplateClient;
|
||||
private VAppClient vappClient;
|
||||
|
||||
private VApp vApp;
|
||||
|
||||
@AfterClass(groups = { "live" })
|
||||
public void cleanUp() throws Exception {
|
||||
if (vApp != null) {
|
||||
vApp = vappClient.getVApp(vApp.getHref()); // update
|
||||
|
||||
// Shutdown and power off the VApp if necessary
|
||||
if (vApp.getStatus().equals(Status.POWERED_ON.getValue())) {
|
||||
try {
|
||||
Task shutdownTask = vappClient.shutdown(vApp.getHref());
|
||||
retryTaskSuccess.apply(shutdownTask);
|
||||
} catch (Exception e) {
|
||||
// keep going; cleanup as much as possible
|
||||
logger.warn(e, "Continuing cleanup after error shutting down VApp %s", vApp);
|
||||
}
|
||||
}
|
||||
|
||||
// Undeploy the VApp if necessary
|
||||
if (vApp.isDeployed()) {
|
||||
try {
|
||||
UndeployVAppParams params = UndeployVAppParams.builder().build();
|
||||
Task undeployTask = vappClient.undeploy(vApp.getHref(), params);
|
||||
retryTaskSuccess.apply(undeployTask);
|
||||
} catch (Exception e) {
|
||||
// keep going; cleanup as much as possible
|
||||
logger.warn(e, "Continuing cleanup after error undeploying VApp %s", vApp);
|
||||
}
|
||||
}
|
||||
|
||||
Task task = vappClient.deleteVApp(vApp.getHref());
|
||||
assertTaskSucceeds(task);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeClass(inheritGroups = true)
|
||||
public void setupRequiredClients() {
|
||||
queryClient = context.getApi().getQueryClient();
|
||||
vappTemplateClient = context.getApi().getVAppTemplateClient();
|
||||
vappClient = context.getApi().getVAppClient();
|
||||
}
|
||||
|
||||
@Test(testName = "GET /catalogs/query")
|
||||
|
@ -83,7 +134,7 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
}
|
||||
|
||||
@Test(testName = "GET /vAppTemplates/query?filter)")
|
||||
public void testQueryVAppTemplates() {
|
||||
public void testQueryVAppTemplatesWithFilter() {
|
||||
VAppTemplate vAppTemplate = vappTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
QueryResultRecords queryResult = queryClient.vAppTemplatesQuery(String.format("name==%s", vAppTemplate.getName()));
|
||||
Set<URI> hrefs = toHrefs(queryResult);
|
||||
|
@ -94,24 +145,58 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
@Test(testName = "GET /vApps/query")
|
||||
public void testQueryAllVApps() {
|
||||
// TODO instantiate a vApp, so can assert it's included
|
||||
vApp = instantiateVApp();
|
||||
|
||||
QueryResultRecords queryResult = queryClient.vAppsQueryAll();
|
||||
Set<URI> hrefs = toHrefs(queryResult);
|
||||
|
||||
assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VAPP, null));
|
||||
//assertTrue(hrefs.contains(vappUri), "VApp query result should include vapp "+vappUri+"; but only has "+hrefs);
|
||||
assertTrue(hrefs.contains(vApp.getHref()), "VApp query result should include vapp "+vApp.getHref()+"; but only has "+hrefs);
|
||||
}
|
||||
|
||||
@Test(testName = "GET /vms/query")
|
||||
public void testQueryAllVms() {
|
||||
// TODO instantiate a vApp + vms, so can assert it's included
|
||||
@Test(testName = "GET /vApps/query?filter", dependsOnMethods = { "testQueryAllVApps" } )
|
||||
public void testQueryVAppsWithFilter() {
|
||||
QueryResultRecords queryResult = queryClient.vAppsQuery(String.format("name==%s", vApp.getName()));
|
||||
Set<URI> hrefs = toHrefs(queryResult);
|
||||
|
||||
assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VAPP, null));
|
||||
assertEquals(hrefs, Collections.singleton(vApp.getHref()), "VApps query result should have found vApp "+vApp.getHref());
|
||||
}
|
||||
|
||||
@Test(testName = "GET /vms/query", dependsOnMethods = { "testQueryAllVApps" } )
|
||||
public void testQueryAllVms() {
|
||||
// Wait for vApp to have been entirely instantiated
|
||||
Task instantiateTask = Iterables.getFirst(vApp.getTasks(), null);
|
||||
if (instantiateTask != null) {
|
||||
assertTaskSucceedsLong(instantiateTask);
|
||||
}
|
||||
|
||||
// Start the vApp so that it has VMs
|
||||
Task task = vappClient.powerOn(vApp.getHref());
|
||||
assertTaskSucceedsLong(task);
|
||||
|
||||
vApp = vappClient.getVApp(vApp.getHref()); // reload, so it has the VMs
|
||||
List<Vm> vms = vApp.getChildren().getVms();
|
||||
Set<URI> vmHrefs = toHrefs(vms);
|
||||
|
||||
// Method under test: do the query
|
||||
QueryResultRecords queryResult = queryClient.vmsQueryAll();
|
||||
Set<URI> hrefs = toHrefs(queryResult);
|
||||
|
||||
assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VM, null));
|
||||
//assertTrue(hrefs.contains(vappUri), "VApp query result should include vapp "+vappUri+"; but only has "+hrefs);
|
||||
assertTrue(hrefs.containsAll(vmHrefs), "VMs query result should include vms "+vmHrefs+"; but only has "+hrefs);
|
||||
}
|
||||
|
||||
@Test(testName = "GET /vms/query?filter", dependsOnMethods = { "testQueryAllVms" } )
|
||||
public void testQueryAllVmsWithFilter() {
|
||||
List<Vm> vms = vApp.getChildren().getVms();
|
||||
Set<URI> vmHrefs = toHrefs(vms);
|
||||
|
||||
QueryResultRecords queryResult = queryClient.vmsQuery(String.format("containerName==%s", vApp.getName()));
|
||||
Set<URI> hrefs = toHrefs(queryResult);
|
||||
|
||||
assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VM, null));
|
||||
assertEquals(hrefs, vmHrefs, "VMs query result should equal vms of vApp "+vApp.getName()+" ("+vmHrefs+"); but only has "+hrefs);
|
||||
}
|
||||
|
||||
private void assertRecordTypes(QueryResultRecords queryResult, Collection<String> validTypes) {
|
||||
|
@ -127,4 +212,12 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
}
|
||||
return hrefs;
|
||||
}
|
||||
|
||||
private Set<URI> toHrefs(Iterable<? extends ResourceType> resources) {
|
||||
Set<URI> hrefs = new LinkedHashSet<URI>();
|
||||
for (ResourceType resource : resources) {
|
||||
hrefs.add(resource.getHref());
|
||||
}
|
||||
return hrefs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,6 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||
|
@ -65,15 +64,12 @@ import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.ControlAccessParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.DeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.InstantiateVAppTemplateParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.InstantiationParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.LeaseSettingsSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.MediaInsertOrEjectParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.NetworkConfigSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.NetworkConnectionSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Owner;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList;
|
||||
|
@ -87,7 +83,6 @@ import org.jclouds.vcloud.director.v1_5.domain.ScreenTicket;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.UndeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppNetworkConfiguration;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VmPendingQuestion;
|
||||
|
@ -107,13 +102,10 @@ import org.testng.annotations.AfterClass;
|
|||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
|
@ -124,10 +116,6 @@ import com.google.common.collect.Iterables;
|
|||
@Test(groups = { "live", "user", "vapp" }, singleThreaded = true, testName = "VAppClientLiveTest")
|
||||
public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||
|
||||
public static final String VAPP = "vApp";
|
||||
public static final String VAPP_TEMPLATE = "vAppTemplate";
|
||||
public static final String VDC = "vdc";
|
||||
|
||||
/*
|
||||
* Convenience reference to API clients.
|
||||
*/
|
||||
|
@ -176,7 +164,7 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
*/
|
||||
@Test(testName = "GET /vApp/{id}")
|
||||
public void testGetVApp() {
|
||||
VApp vAppInstantiated = instantiateVApp();
|
||||
VApp vAppInstantiated = instantiateVApp("test-vapp");
|
||||
|
||||
// Wait for the task to complete
|
||||
Task instantiateTask = Iterables.getOnlyElement(vAppInstantiated.getTasks());
|
||||
|
@ -1211,77 +1199,6 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a {@link VApp} in a {@link Vdc} using the {@link VAppTemplate} we have configured for the tests.
|
||||
*
|
||||
* @return the VApp that is being instantiated
|
||||
*/
|
||||
private VApp instantiateVApp() {
|
||||
InstantiateVAppTemplateParams instantiate = InstantiateVAppTemplateParams.builder()
|
||||
.name("test-vapp")
|
||||
.notDeploy()
|
||||
.notPowerOn()
|
||||
.description("Test VApp")
|
||||
.instantiationParams(instantiationParams())
|
||||
.source(Reference.builder().href(vAppTemplateURI).build())
|
||||
.build();
|
||||
|
||||
VApp vAppInstantiated = vdcClient.instantiateVApp(vdcURI, instantiate);
|
||||
assertNotNull(vAppInstantiated, String.format(ENTITY_NON_NULL, VAPP));
|
||||
|
||||
return vAppInstantiated;
|
||||
}
|
||||
|
||||
/** Build an {@link InstantiationParams} object. */
|
||||
private InstantiationParams instantiationParams() {
|
||||
InstantiationParams instantiationParams = InstantiationParams.builder()
|
||||
.sections(ImmutableSet.of(networkConfigSection()))
|
||||
.build();
|
||||
|
||||
return instantiationParams;
|
||||
}
|
||||
|
||||
/** Build a {@link NetworkConfigSection} object. */
|
||||
private NetworkConfigSection networkConfigSection() {
|
||||
NetworkConfigSection networkConfigSection = NetworkConfigSection.builder()
|
||||
.info("Configuration parameters for logical networks")
|
||||
.networkConfigs(
|
||||
ImmutableSet.of(
|
||||
VAppNetworkConfiguration.builder()
|
||||
.networkName("vAppNetwork")
|
||||
.configuration(networkConfiguration())
|
||||
.build()))
|
||||
.build();
|
||||
|
||||
return networkConfigSection;
|
||||
}
|
||||
|
||||
/** Build a {@link NetworkConfiguration} object. */
|
||||
private NetworkConfiguration networkConfiguration() {
|
||||
Set<Reference> networks = vdc.getAvailableNetworks().getNetworks();
|
||||
|
||||
// Look up the network in the Vdc with the id configured for the tests
|
||||
Optional<Reference> parentNetwork = Iterables.tryFind(networks, new Predicate<Reference>() {
|
||||
@Override
|
||||
public boolean apply(Reference reference) {
|
||||
return reference.getHref().equals(networkURI);
|
||||
}
|
||||
});
|
||||
|
||||
// Check we actually found a network reference
|
||||
if (!parentNetwork.isPresent()) {
|
||||
fail(String.format("Could not find network %s in vdc", networkURI.toASCIIString()));
|
||||
}
|
||||
|
||||
// Build the configuration object
|
||||
NetworkConfiguration networkConfiguration = NetworkConfiguration.builder()
|
||||
.parentNetwork(parentNetwork.get())
|
||||
.fenceMode("bridged")
|
||||
.build();
|
||||
|
||||
return networkConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshals a JAXB annotated object into XML. The XML is output on {@link System#err}.
|
||||
*/
|
||||
|
|
|
@ -18,17 +18,25 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.director.v1_5.internal;
|
||||
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_NON_NULL;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.compute.BaseVersionedServiceLiveTest;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
@ -38,11 +46,20 @@ import org.jclouds.vcloud.director.testng.FormatApiResultsListener;
|
|||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.InstantiateVAppTemplateParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.InstantiationParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Link;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.NetworkConfigSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Org;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Session;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppNetworkConfiguration;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VdcClient;
|
||||
import org.jclouds.vcloud.director.v1_5.predicates.ReferenceTypePredicates;
|
||||
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
@ -50,6 +67,7 @@ import org.testng.annotations.BeforeGroups;
|
|||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Strings;
|
||||
|
@ -69,9 +87,34 @@ import com.google.inject.Module;
|
|||
@Test(groups = "live")
|
||||
public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected static final long TASK_TIMEOUT_SECONDS = 10L;
|
||||
protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L;
|
||||
|
||||
public static final String VAPP = "vApp";
|
||||
public static final String VAPP_TEMPLATE = "vAppTemplate";
|
||||
public static final String VDC = "vdc";
|
||||
|
||||
public Predicate<Task> retryTaskSuccess;
|
||||
public Predicate<Task> retryTaskSuccessLong;
|
||||
|
||||
protected RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context;
|
||||
protected Session session;
|
||||
|
||||
protected String catalogName;
|
||||
protected String networkName;
|
||||
protected String userName;
|
||||
|
||||
protected URI vAppTemplateURI;
|
||||
protected URI mediaURI;
|
||||
protected URI networkURI;
|
||||
protected URI vdcURI;
|
||||
protected URI userURI;
|
||||
|
||||
protected Random random = new Random();
|
||||
|
||||
protected BaseVCloudDirectorClientLiveTest() {
|
||||
provider = "vcloud-director";
|
||||
}
|
||||
|
@ -83,13 +126,10 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
dateService = Guice.createInjector().getInstance(DateService.class);
|
||||
assertNotNull(dateService);
|
||||
}
|
||||
|
||||
|
||||
// NOTE Implement as required to populate xxxClient fields, or NOP
|
||||
protected abstract void setupRequiredClients() throws Exception;
|
||||
|
||||
public Predicate<Task> retryTaskSuccess;
|
||||
public Predicate<Task> retryTaskSuccessLong;
|
||||
|
||||
@Inject
|
||||
protected void initTaskSuccess(TaskSuccess taskSuccess) {
|
||||
retryTaskSuccess = new RetryablePredicate<Task>(taskSuccess, TASK_TIMEOUT_SECONDS * 10000L);
|
||||
|
@ -100,9 +140,6 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
retryTaskSuccessLong = new RetryablePredicate<Task>(taskSuccess, LONG_TASK_TIMEOUT_SECONDS * 1000L);
|
||||
}
|
||||
|
||||
protected RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context;
|
||||
protected Session session;
|
||||
|
||||
@BeforeClass(groups = { "live" })
|
||||
protected void setupContext() throws Exception {
|
||||
setupCredentials();
|
||||
|
@ -116,18 +153,6 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
setupRequiredClients();
|
||||
}
|
||||
|
||||
protected String catalogName;
|
||||
protected String networkName;
|
||||
protected String userName;
|
||||
|
||||
protected URI vAppTemplateURI;
|
||||
protected URI mediaURI;
|
||||
protected URI networkURI;
|
||||
protected URI vdcURI;
|
||||
protected URI userURI;
|
||||
|
||||
protected Random random = new Random();
|
||||
|
||||
// TODO change properties to URI, not id
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void initTestParametersFromPropertiesOrLazyDiscover() {
|
||||
|
@ -189,10 +214,90 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
}
|
||||
|
||||
protected void assertTaskSucceeds(Task task) {
|
||||
assertTrue(retryTaskSuccess.apply(task));
|
||||
assertTrue(retryTaskSuccess.apply(task), String.format(TASK_COMPLETE_TIMELY, task));
|
||||
}
|
||||
|
||||
protected void assertTaskSucceedsLong(Task task) {
|
||||
assertTrue(retryTaskSuccessLong.apply(task));
|
||||
assertTrue(retryTaskSuccessLong.apply(task), String.format(TASK_COMPLETE_TIMELY, task));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a {@link VApp} in a {@link Vdc} using the {@link VAppTemplate} we have configured for the tests.
|
||||
*
|
||||
* @return the VApp that is being instantiated
|
||||
*/
|
||||
protected VApp instantiateVApp() {
|
||||
return instantiateVApp("test-vapp-"+random.nextInt(Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
protected VApp instantiateVApp(String name) {
|
||||
InstantiateVAppTemplateParams instantiate = InstantiateVAppTemplateParams.builder()
|
||||
.name(name)
|
||||
.notDeploy()
|
||||
.notPowerOn()
|
||||
.description("Test VApp")
|
||||
.instantiationParams(instantiationParams())
|
||||
.source(Reference.builder().href(vAppTemplateURI).build())
|
||||
.build();
|
||||
|
||||
VdcClient vdcClient = context.getApi().getVdcClient();
|
||||
VApp vAppInstantiated = vdcClient.instantiateVApp(vdcURI, instantiate);
|
||||
assertNotNull(vAppInstantiated, String.format(ENTITY_NON_NULL, VAPP));
|
||||
|
||||
return vAppInstantiated;
|
||||
}
|
||||
|
||||
/** Build an {@link InstantiationParams} object. */
|
||||
private InstantiationParams instantiationParams() {
|
||||
InstantiationParams instantiationParams = InstantiationParams.builder()
|
||||
.sections(ImmutableSet.of(networkConfigSection()))
|
||||
.build();
|
||||
|
||||
return instantiationParams;
|
||||
}
|
||||
|
||||
/** Build a {@link NetworkConfigSection} object. */
|
||||
private NetworkConfigSection networkConfigSection() {
|
||||
NetworkConfigSection networkConfigSection = NetworkConfigSection.builder()
|
||||
.info("Configuration parameters for logical networks")
|
||||
.networkConfigs(
|
||||
ImmutableSet.of(
|
||||
VAppNetworkConfiguration.builder()
|
||||
.networkName("vAppNetwork")
|
||||
.configuration(networkConfiguration())
|
||||
.build()))
|
||||
.build();
|
||||
|
||||
return networkConfigSection;
|
||||
}
|
||||
|
||||
/** Build a {@link NetworkConfiguration} object. */
|
||||
private NetworkConfiguration networkConfiguration() {
|
||||
Vdc vdc = context.getApi().getVdcClient().getVdc(vdcURI);
|
||||
assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC));
|
||||
|
||||
Set<Reference> networks = vdc.getAvailableNetworks().getNetworks();
|
||||
|
||||
// Look up the network in the Vdc with the id configured for the tests
|
||||
Optional<Reference> parentNetwork = Iterables.tryFind(networks, new Predicate<Reference>() {
|
||||
@Override
|
||||
public boolean apply(Reference reference) {
|
||||
return reference.getHref().equals(networkURI);
|
||||
}
|
||||
});
|
||||
|
||||
// Check we actually found a network reference
|
||||
if (!parentNetwork.isPresent()) {
|
||||
fail(String.format("Could not find network %s in vdc", networkURI.toASCIIString()));
|
||||
}
|
||||
|
||||
// Build the configuration object
|
||||
NetworkConfiguration networkConfiguration = NetworkConfiguration.builder()
|
||||
.parentNetwork(parentNetwork.get())
|
||||
.fenceMode("bridged")
|
||||
.build();
|
||||
|
||||
return networkConfiguration;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue