use of com.vmware.xenon.common.ServiceHost.ServiceNotFoundException in project photon-model by vmware.
the class AWSMissingResourcesEnumerationService method createLinkedComputeStates.
/**
* creates new linked account endpoint states of a primary account
* @param context
*/
private void createLinkedComputeStates(AwsMissingResourcesEnumContext context) {
AtomicInteger completionCounter = new AtomicInteger(context.request.missingLinkedAccountIds.size());
AtomicBoolean isSuccessful = new AtomicBoolean(true);
context.request.missingLinkedAccountIds.forEach(linkedAccountId -> {
ComputeDescription computeDescription = populateComputeDescription(context, linkedAccountId);
ComputeState computeState = populateComputeState(context, linkedAccountId);
computeState.descriptionLink = computeDescription.documentSelfLink;
Operation csOp = Operation.createPost(this, ComputeService.FACTORY_LINK).setBody(computeState);
Operation cdOp = Operation.createPost(this, ComputeDescriptionService.FACTORY_LINK).setBody(computeDescription);
JoinedCompletionHandler completionHandler = (ops, exs) -> {
if (exs != null && !exs.isEmpty()) {
logWarning(() -> String.format("Error creating missing resources for" + " account with ID %s.", linkedAccountId));
isSuccessful.set(false);
} else {
logInfo(() -> String.format("Created missing resources for account " + "with ID %s.", linkedAccountId));
}
if (completionCounter.decrementAndGet() == 0) {
if (isSuccessful.get()) {
context.requestOp.complete();
} else {
context.requestOp.fail(new Exception("Failed to create missing resources " + "for atleast one linked account."));
}
}
};
Operation.createGet(this, computeDescription.documentSelfLink).setReferer(this.getUri()).setCompletion((o, e) -> {
if (e != null && (e instanceof ServiceNotFoundException || o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND)) {
OperationSequence.create(cdOp).next(csOp).setCompletion(completionHandler).sendWith(this);
} else {
OperationSequence.create(csOp).setCompletion(completionHandler).sendWith(this);
}
}).sendWith(this);
});
}
use of com.vmware.xenon.common.ServiceHost.ServiceNotFoundException in project photon-model by vmware.
the class TestProvisionAWSSecurityGroup method testProvisionAWSSecurityGroupPartialFailure.
@Test
public void testProvisionAWSSecurityGroupPartialFailure() throws Throwable {
// create credentials
Operation authResponse = new Operation();
TestUtils.postCredentials(this.host, authResponse, this.privateKey, this.privateKeyId);
AuthCredentialsServiceState creds = authResponse.getBody(AuthCredentialsServiceState.class);
// create resource pool
Operation poolResponse = new Operation();
TestUtils.postResourcePool(this.host, poolResponse);
ResourcePoolState pool = poolResponse.getBody(ResourcePoolState.class);
// create two security groups
Operation securityGroupResponse = new Operation();
SecurityGroupState initialSecurityGroupState = buildSecurityGroupState(creds, pool);
TestUtils.postSecurityGroup(this.host, initialSecurityGroupState, securityGroupResponse);
SecurityGroupState securityGroupState1 = securityGroupResponse.getBody(SecurityGroupState.class);
initialSecurityGroupState = buildSecurityGroupState(creds, pool);
TestUtils.postSecurityGroup(this.host, initialSecurityGroupState, securityGroupResponse);
SecurityGroupState securityGroupState2 = securityGroupResponse.getBody(SecurityGroupState.class);
// delete the second security group to simulate failure
TestUtils.deleteSecurityGroup(this.host, securityGroupState2.documentSelfLink);
// verify the second security group is gone
try {
getSecurityGroupState(securityGroupState2.documentSelfLink);
} catch (Exception ex) {
assertTrue(ex instanceof ServiceNotFoundException);
}
// set up security group task state
ProvisionSecurityGroupTaskState task = new ProvisionSecurityGroupTaskState();
task.requestType = SecurityGroupInstanceRequest.InstanceRequestType.CREATE;
task.securityGroupDescriptionLinks = Stream.of(securityGroupState1.documentSelfLink, securityGroupState2.documentSourceLink).collect(Collectors.toSet());
task.customProperties = new HashMap<>();
task.customProperties.put(NETWORK_STATE_ID_PROP_NAME, this.vpcId);
Operation provision = new Operation();
provisionSecurityGroup(task, provision);
ProvisionSecurityGroupTaskState ps = provision.getBody(ProvisionSecurityGroupTaskState.class);
waitForTaskFailure(this.host, UriUtils.buildUri(this.host, ps.documentSelfLink));
validateAWSArtifacts(securityGroupState1.documentSelfLink, creds);
// validate that the second security group was not created
assertNull(getAWSSecurityGroup(securityGroupState2.name, creds));
// reuse previous task, but switch to a delete
task.requestType = SecurityGroupInstanceRequest.InstanceRequestType.DELETE;
Operation remove = new Operation();
provisionSecurityGroup(task, remove);
ProvisionSecurityGroupTaskState removeTask = remove.getBody(ProvisionSecurityGroupTaskState.class);
waitForTaskFailure(this.host, UriUtils.buildUri(this.host, removeTask.documentSelfLink));
// verify security group state is gone
try {
getSecurityGroupState(securityGroupState1.documentSelfLink);
} catch (Exception ex) {
assertTrue(ex instanceof ServiceNotFoundException);
}
}
use of com.vmware.xenon.common.ServiceHost.ServiceNotFoundException in project photon-model by vmware.
the class AzureSecurityGroupServiceTest method testDeleteSecurityGroup.
@Test
public void testDeleteSecurityGroup() throws Throwable {
SecurityGroupState securityGroupState = provisionSecurityGroup(new ArrayList<>(), new ArrayList<>(), TaskStage.FINISHED);
startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
// verify security group state was deleted
try {
getSecurityGroupState(this.host, securityGroupState.documentSelfLink);
} catch (Exception e) {
assertTrue(e instanceof ServiceNotFoundException);
}
if (!this.isMock) {
// Verify that the security group was deleted from Azure.
NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
if (sgResponse != null) {
fail("Security group should not exist in Azure.");
}
}
}
use of com.vmware.xenon.common.ServiceHost.ServiceNotFoundException in project photon-model by vmware.
the class AzureSecurityGroupServiceTest method testDeleteMissingSecurityGroup.
@Test
public void testDeleteMissingSecurityGroup() throws Throwable {
SecurityGroupState securityGroupState = createSecurityGroupState(this.securityGroupName, new ArrayList<>(), new ArrayList<>());
// attempt to delete the missing SG
startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
// verify security group state was deleted
try {
getSecurityGroupState(this.host, securityGroupState.documentSelfLink);
} catch (Exception e) {
assertTrue(e instanceof ServiceNotFoundException);
}
}
use of com.vmware.xenon.common.ServiceHost.ServiceNotFoundException in project photon-model by vmware.
the class VSphereResourcePoolEnumerationHelper method processFoundResourcePool.
public static void processFoundResourcePool(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, ResourcePoolOverlay rp, String ownerName, EnumerationClient client) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
String selfLink = buildStableResourcePoolLink(rp.getId(), request.endpointLink);
Operation.createGet(PhotonModelUriUtils.createInventoryUri(service.getHost(), selfLink)).setCompletion((o, e) -> {
try {
if (e == null) {
updateResourcePool(service, enumerationProgress, ownerName, selfLink, rp, true, client);
} else if (e instanceof ServiceNotFoundException || o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) {
createNewResourcePool(service, enumerationProgress, ownerName, selfLink, rp, client);
} else {
enumerationProgress.getResourcePoolTracker().track();
}
} catch (Exception ex) {
enumerationProgress.getResourcePoolTracker().track(rp.getId(), ResourceTracker.ERROR);
}
}).sendWith(service);
}
Aggregations