use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AWSResetServiceTest method setVMSecurityGroupsToBeDeleted.
private void setVMSecurityGroupsToBeDeleted(Instance instance, ComputeState vm) {
// This assert is only suitable for real (non-mocking env).
if (this.isMock) {
return;
}
// Get the SecurityGroupStates that were provided in the request ComputeState
Collector<SecurityGroupState, ?, Map<String, SecurityGroupState>> convertToMap = Collectors.<SecurityGroupState, String, SecurityGroupState>toMap(sg -> sg.name, sg -> sg);
Map<String, SecurityGroupState> currentSGNamesToStates = vm.networkInterfaceLinks.stream().map(nicLink -> this.host.getServiceState(null, NetworkInterfaceState.class, UriUtils.buildUri(this.host, nicLink))).<// collect all SecurityGroup States from all NIC states
SecurityGroupState>flatMap(nicState -> nicState.securityGroupLinks.stream().map(sgLink -> {
SecurityGroupState sgState = this.host.getServiceState(null, SecurityGroupState.class, UriUtils.buildUri(this.host, sgLink));
return sgState;
})).collect(convertToMap);
for (SecurityGroupState currentSGState : currentSGNamesToStates.values()) {
// Ensure that the requested SecurityGroup was actually provisioned
if (currentSGState.name.contains(TestAWSSetupUtils.AWS_NEW_GROUP_PREFIX)) {
this.sgToCleanUp = currentSGState.id;
}
}
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class LongRunEndToEndStatsAggregationTest method verifyResourceMetricEntries.
/**
* Performs check to verify appropriate resource metrics entries are present for
* compute resources.
*/
private void verifyResourceMetricEntries(ServiceDocumentQueryResult res) {
for (Map.Entry<String, Object> resourceMap : res.documents.entrySet()) {
ComputeState state = Utils.fromJson(resourceMap.getValue(), ComputeState.class);
if (state.type == ComputeType.ENDPOINT_HOST) {
assertNotNull(getResourceMetrics(resourceMap.getKey(), PhotonModelConstants.ESTIMATED_CHARGES));
} else if (state.type == ComputeType.VM_GUEST) {
long micros = Utils.getNowMicrosUtc() - state.creationTimeMicros;
if (state.powerState == PowerState.ON && micros > TimeUnit.MINUTES.toMicros(initTimeForStatsAvailInMin)) {
assertNotNull(getResourceMetrics(resourceMap.getKey(), PhotonModelConstants.CPU_UTILIZATION_PERCENT));
}
} else if (state.type == ComputeType.ZONE) {
assertNotNull(getResourceMetrics(resourceMap.getKey(), PhotonModelConstants.ESTIMATED_CHARGES));
} else {
assertNull(getResourceMetrics(resourceMap.getKey(), PhotonModelConstants.ESTIMATED_CHARGES));
assertNull(getResourceMetrics(resourceMap.getKey(), PhotonModelConstants.CPU_UTILIZATION_PERCENT));
}
}
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class TestAWSEnumerationDocumentCountInLongRun method storeDocumentLinksFromComputeStates.
/**
* Gets and stores resource pool links and network interface links by querying
* given instance IDs.
* @param instanceIdList List of instance IDs provisioned by the test
*/
private void storeDocumentLinksFromComputeStates(List<String> instanceIdList) {
// Query to get all compute state documents associated with list of instance IDs.
QueryTask.Query computeStateQuery = QueryTask.Query.Builder.create().addKindFieldClause(ComputeState.class).addInClause(ComputeState.FIELD_NAME_ID, instanceIdList).build();
QueryTask q = QueryTask.Builder.createDirectTask().setQuery(computeStateQuery).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).build();
Operation queryComputeState = QueryUtils.createQueryTaskOperation(this.host, q, ServiceTypeCluster.INVENTORY_SERVICE).setReferer(this.host.getUri());
Operation queryResponse = this.host.waitForResponse(queryComputeState);
Assert.assertTrue("Error retrieving compute states", queryResponse.getStatusCode() == 200);
QueryTask qt = queryResponse.getBody(QueryTask.class);
// Store all compute links
this.computeStateLinks.addAll(qt.results.documentLinks);
// Store resource pool links and network links from all compute states.
for (String documentLink : this.computeStateLinks) {
ComputeState cs = Utils.fromJson(qt.results.documents.get(documentLink), ComputeState.class);
this.resourcePoolLinks.add(cs.resourcePoolLink);
this.networkInterfaceLinks.addAll(cs.networkInterfaceLinks);
}
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AWSEnumerationAndDeletionAdapterService method populateLocalInstanceInformationFromQueryResults.
/**
* Populates the local instance information from the query results.
*/
public QueryTask populateLocalInstanceInformationFromQueryResults(EnumerationDeletionContext context, QueryTask queryTask) {
for (Object s : queryTask.results.documents.values()) {
ComputeState localInstance = Utils.fromJson(s, ComputeState.class);
if (!localInstance.id.startsWith(AWS_INSTANCE_ID_PREFIX)) {
continue;
}
context.localInstanceIds.put(localInstance.id, localInstance);
}
context.pageNo++;
context.nextPageLink = queryTask.results.nextPageLink;
logFine(() -> String.format("Next page link %s", context.nextPageLink));
return queryTask;
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AWSEnumerationAndDeletionAdapterService method retireComputeStates.
/**
* Creates operations to retire all the compute states in the local system for which the AWS
* instance has been terminated/missing from the remote instance.
*/
private void retireComputeStates(EnumerationDeletionContext context) {
List<Operation> operations = new ArrayList<>();
// Disks.
for (ComputeState cs : context.instancesToBeDeleted) {
ComputeState cps = new ComputeState();
cps.powerState = PowerState.OFF;
cps.lifecycleState = LifecycleState.RETIRED;
Operation operation = Operation.createPatch(this.getHost(), cs.documentSelfLink).setBody(cps).setReferer(getHost().getUri());
operations.add(operation);
}
// Kick off patch operations with a join handler.
if (operations == null || operations.size() == 0) {
logFine(() -> "No local compute states to be deleted.");
deleteResourcesInLocalSystem(context);
return;
}
OperationJoin.JoinedCompletionHandler joinCompletion = (ox, exc) -> {
if (exc != null) {
logSevere(() -> String.format("Failure retiring local compute states: %s ", Utils.toString(exc)));
deleteResourcesInLocalSystem(context);
return;
}
logFine(() -> "Successfully retired local compute states.");
deleteResourcesInLocalSystem(context);
return;
};
OperationJoin joinOp = OperationJoin.create(operations);
joinOp.setCompletion(joinCompletion);
joinOp.sendWith(getHost());
}
Aggregations