use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class TestVSphereOvfImport method importOvfAsDescriptions.
@Test
public void importOvfAsDescriptions() throws Throwable {
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
createComputeHost();
ComputeDescription computeDesc = new ComputeDescription();
computeDesc.supportedChildren = new ArrayList<>();
computeDesc.instanceAdapterReference = UriUtils.buildUri(this.host, VSphereUriPaths.INSTANCE_SERVICE);
computeDesc.authCredentialsLink = this.auth.documentSelfLink;
computeDesc.name = computeDesc.id;
computeDesc.dataStoreId = this.dataStoreId;
ImportOvfRequest req = new ImportOvfRequest();
req.ovfUri = new File("src/test/resources/vcenter.ovf").toURI();
req.template = computeDesc;
Operation op = Operation.createPatch(this.host, OvfImporterService.SELF_LINK).setBody(req).setReferer(this.host.getPublicUri());
op = this.host.waitForResponse(op);
assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
Query q = Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_ID, "ovf-", MatchType.PREFIX).build();
QueryTask task = QueryTask.Builder.createDirectTask().setQuery(q).build();
QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
task = this.host.waitForResponse(op).getBody(QueryTask.class);
assertTrue(task.results.documentLinks.size() > 5);
snapshotFactoryState("ovf", ComputeDescriptionService.class);
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class EnumerationClientTest method test.
@Test
public void test() throws Exception {
String url = System.getProperty(TestProperties.VC_URL);
if (url == null) {
return;
}
String username = System.getProperty(TestProperties.VC_USERNAME);
String password = System.getProperty(TestProperties.VC_PASSWORD);
String datacenter = System.getProperty(TestProperties.VC_DATECENTER_ID);
ManagedObjectReference datacenterMoRef = VimUtils.convertStringToMoRef(datacenter);
BasicConnection conn = new BasicConnection();
conn.setURI(URI.create(url));
conn.setUsername(username);
conn.setPassword(password);
conn.setIgnoreSslErrors(true);
conn.setRequestTimeout(30, TimeUnit.SECONDS);
conn.connect();
ComputeStateWithDescription parent = new ComputeStateWithDescription();
ComputeDescription desc = new ComputeDescription();
parent.description = desc;
EnumerationClient client = new EnumerationClient(conn, parent);
PropertyFilterSpec spec = client.createResourcesFilterSpec();
for (List<ObjectContent> page : client.retrieveObjects(spec)) {
for (ObjectContent cont : page) {
this.logger.info(VimUtils.convertMoRefToString(cont.getObj()));
}
}
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class CustomPropertiesTest method putAndGetDescription.
@Test
public void putAndGetDescription() {
ManagedObjectReference ref = new ManagedObjectReference();
ref.setType("type");
ref.setValue("v1");
ComputeDescription desc = new ComputeDescription();
CustomProperties.of(desc).put("12", 12).put("s", "s").put("4", 4L).put("ref", ref);
assertEquals("12", desc.customProperties.get("12"));
assertEquals("4", desc.customProperties.get("4"));
assertEquals("s", desc.customProperties.get("s"));
assertEquals(VimUtils.convertMoRefToString(ref), desc.customProperties.get("ref"));
CustomProperties access = CustomProperties.of(desc);
assertEquals((Integer) 12, access.getInt("12", null));
assertEquals("s", access.getString("s"));
assertEquals(Long.valueOf(4), access.getLong("4", null));
assertMoFefEquals(ref, access.getMoRef("ref"));
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class OvfParser method parse.
/**
* Produces several descriptions based on the different hardware configuration defined in the
* OVF descriptor.
*
* @param doc
* OVF descriptor to parse
* @param template
* use as a basis of the ComputeDescription.
* @return
*/
public List<ComputeDescription> parse(Document doc, ComputeDescription template) {
CustomProperties cust = CustomProperties.of(template);
NodeList props = nodes(doc, "/ovf:Envelope/ovf:VirtualSystem/ovf:ProductSection/ovf:Property");
for (Element prop : iterableElements(props)) {
String userConfigurable = attr("ovf:userConfigurable", prop);
if (!"true".equals(userConfigurable)) {
continue;
}
String key = attr("ovf:key", prop);
Element section = (Element) prop.getParentNode();
String instanceId = attr("ovf:instance", section);
String classId = attr("ovf:class", section);
String description = text(prop, "ovf:Description/text()");
cust.put(property(classId, key, instanceId), description);
}
if (template.name == null) {
String productName = text(doc, "/ovf:Envelope/ovf:VirtualSystem/ovf:ProductSection/ovf:Product/text()");
String productVersion = text(doc, "/ovf:Envelope/ovf:VirtualSystem/ovf:ProductSection/ovf:Version/text()");
template.name = productName + " " + productVersion;
}
NodeList hwItems = nodes(doc, "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item");
Map<String, ComputeDescription> hwByConfigName = new HashMap<>();
for (Element item : iterableElements(hwItems)) {
String configName = attr("ovf:configuration", item);
ComputeDescription desc = hwByConfigName.get(configName);
if (desc == null) {
desc = Utils.clone(template);
desc.documentSelfLink = UUID.randomUUID().toString();
desc.id = "ovf-imported-" + desc.documentSelfLink;
desc.customProperties.put(PROP_OVF_CONFIGURATION, configName);
hwByConfigName.put(configName, desc);
}
String resourceType = text(item, "rasd:ResourceType/text()");
if (RESOURCE_TYPE_CPU.equals(resourceType)) {
long qty = Long.parseLong(text(item, "rasd:VirtualQuantity/text()"));
desc.cpuCount = qty;
}
if (RESOURCE_TYPE_MEMORY.equals(resourceType)) {
double qty = Double.parseDouble(text(item, "rasd:VirtualQuantity/text()"));
long mult = memAllocationUnit2Multiplier(text(item, "rasd:AllocationUnits/text()"));
desc.totalMemoryBytes = (long) (qty * mult);
}
}
for (Iterator<ComputeDescription> it = hwByConfigName.values().iterator(); it.hasNext(); ) {
ComputeDescription desc = it.next();
if (desc.cpuCount <= 0) {
it.remove();
}
}
return new ArrayList<>(hwByConfigName.values());
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class SingleResourceStatsAggregationTaskServiceTest method testResourceStatsAggregation.
@Test
public void testResourceStatsAggregation() throws Throwable {
// create a resource pool
ResourcePoolState rpState = new ResourcePoolState();
rpState.name = "testName";
ResourcePoolState rpReturnState = postServiceSynchronously(ResourcePoolService.FACTORY_LINK, rpState, ResourcePoolState.class);
ComputeState[] computeStateArray = new ComputeState[NUM_COMPUTE_RESOURCES];
for (int i = 0; i < NUM_COMPUTE_RESOURCES; i++) {
ComputeDescription cDesc = new ComputeDescription();
cDesc.name = rpState.name;
cDesc.statsAdapterReference = UriUtils.buildUri(this.host, MockStatsAdapter.SELF_LINK);
ComputeDescription descReturnState = postServiceSynchronously(ComputeDescriptionService.FACTORY_LINK, cDesc, ComputeDescription.class);
ComputeState computeState = new ComputeState();
computeState.name = rpState.name;
computeState.descriptionLink = descReturnState.documentSelfLink;
computeState.resourcePoolLink = rpReturnState.documentSelfLink;
computeStateArray[i] = postServiceSynchronously(ComputeService.FACTORY_LINK, computeState, ComputeState.class);
}
StatsCollectionTaskState collectionTaskState = new StatsCollectionTaskState();
collectionTaskState.resourcePoolLink = rpReturnState.documentSelfLink;
collectionTaskState.taskInfo = TaskState.createDirect();
int counter = 0;
// executing stats collection multiple times
while (counter < NUM_COLLECTIONS) {
this.postServiceSynchronously(StatsCollectionTaskService.FACTORY_LINK, collectionTaskState, StatsCollectionTaskState.class);
counter++;
}
// wait for stats to be populated
this.host.waitFor("Error waiting for stats", () -> {
boolean returnStatus = false;
for (int i = 0; i < NUM_COMPUTE_RESOURCES; i++) {
String statsUriPath = UriUtils.buildUriPath(computeStateArray[i].documentSelfLink, ServiceHost.SERVICE_URI_SUFFIX_STATS);
ServiceStats resStats = getServiceSynchronously(statsUriPath, ServiceStats.class);
for (ServiceStat stat : resStats.entries.values()) {
if (stat.name.startsWith(UriUtils.getLastPathSegment(MockStatsAdapter.SELF_LINK))) {
returnStatus = true;
break;
}
}
}
return returnStatus;
});
// number of keys = 2, number of lastCollectionTimeMetrics = 2
int numberOfRawMetrics = NUM_COLLECTIONS * NUM_COMPUTE_RESOURCES * 2 * 2;
// kick off an aggregation task
SingleResourceStatsAggregationTaskState aggregationTaskState = new SingleResourceStatsAggregationTaskState();
aggregationTaskState.resourceLink = computeStateArray[0].documentSelfLink;
aggregationTaskState.metricNames = new HashSet<>(Arrays.asList(MockStatsAdapter.KEY_1, MockStatsAdapter.KEY_2, MockStatsAdapter.KEY_3));
postServiceSynchronously(SingleResourceStatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, SingleResourceStatsAggregationTaskState.class);
long expectedExpirationTime = Utils.getNowMicrosUtc() + TimeUnit.DAYS.toMicros(DEFAULT_RETENTION_LIMIT_DAYS);
this.host.waitFor("Error waiting for rolled up stats", () -> {
ServiceDocumentQueryResult result = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, ResourceMetricsService.FACTORY_LINK));
String randomDocumentLink = result.documentLinks.get(0);
ResourceMetrics metric = Utils.fromJson(result.documents.get(randomDocumentLink), ResourceMetrics.class);
// Make sure all the documents have expiration time set.
Assert.assertTrue("Expiration time is not correctly set.", metric.documentExpirationTimeMicros < expectedExpirationTime);
return (result.documentCount == 2 + numberOfRawMetrics);
});
String statsUriPath = UriUtils.buildUriPath(computeStateArray[0].documentSelfLink, ServiceHost.SERVICE_URI_SUFFIX_STATS);
ServiceStats resStats = getServiceSynchronously(statsUriPath, ServiceStats.class);
int statCount = 0;
for (ServiceStat stat : resStats.entries.values()) {
if (stat.name.startsWith(MockStatsAdapter.KEY_1) || stat.name.startsWith(MockStatsAdapter.KEY_2)) {
statCount++;
}
}
Assert.assertEquals("Did not find in-memory stats", 2, statCount);
// verify that the aggregation tasks have been deleted
this.host.waitFor("Timeout waiting for task to expire", () -> {
ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildUri(this.host, SingleResourceStatsAggregationTaskService.FACTORY_LINK));
return res.documentLinks.size() == 0;
});
}
Aggregations