Search in sources :

Example 1 with ServiceNotFoundException

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);
    });
}
Also used : JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) UUID(java.util.UUID) JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) StandardCharsets(java.nio.charset.StandardCharsets) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) HashSet(java.util.HashSet) AWSConstants(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants) Utils(com.vmware.xenon.common.Utils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) OperationSequence(com.vmware.xenon.common.OperationSequence) AWSUriPaths(com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) Operation(com.vmware.xenon.common.Operation) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)

Example 2 with ServiceNotFoundException

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);
    }
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ProvisionSecurityGroupTaskState(com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) Operation(com.vmware.xenon.common.Operation) TimeoutException(java.util.concurrent.TimeoutException) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) CompletionException(java.util.concurrent.CompletionException) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 3 with 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.");
        }
    }
}
Also used : NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 4 with ServiceNotFoundException

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);
    }
}
Also used : AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 5 with 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);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) List(java.util.List) UriUtils.buildUriPath(com.vmware.xenon.common.UriUtils.buildUriPath) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) Collections(java.util.Collections) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)

Aggregations

ServiceNotFoundException (com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)8 Operation (com.vmware.xenon.common.Operation)6 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)5 Test (org.junit.Test)5 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)4 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)3 ProvisionSecurityGroupTaskState (com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState)3 UriUtils (com.vmware.xenon.common.UriUtils)3 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)3 CompletionException (java.util.concurrent.CompletionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)2 AzureTestUtil.getSecurityGroupState (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState)2 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)2 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)2 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)2 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)2 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)2 QueryTask (com.vmware.xenon.services.common.QueryTask)2 List (java.util.List)2