Search in sources :

Example 6 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState 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 7 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class AWSMissingResourcesEnumerationService method populateComputeState.

/**
 * creates compute state for the identified linked account
 * @return
 */
private ComputeState populateComputeState(AwsMissingResourcesEnumContext context, String linkedAccountId) {
    ComputeState computeState = new ComputeState();
    computeState.id = generateUuidFromStr(linkedAccountId + context.request.primaryAccountCompute.endpointLink);
    ComputeState primaryAccountCompute = context.request.primaryAccountCompute;
    computeState.name = primaryAccountCompute.name + "_" + linkedAccountId;
    computeState.resourcePoolLink = primaryAccountCompute.resourcePoolLink;
    computeState.type = primaryAccountCompute.type;
    computeState.adapterManagementReference = primaryAccountCompute.adapterManagementReference;
    computeState.tenantLinks = primaryAccountCompute.tenantLinks;
    computeState.creationTimeMicros = Utils.getNowMicrosUtc();
    computeState.customProperties = new HashMap<>();
    computeState.customProperties.put(AWSConstants.AWS_ACCOUNT_ID_KEY, linkedAccountId);
    computeState.customProperties.put(EndpointAllocationTaskService.CUSTOM_PROP_ENPOINT_TYPE, primaryAccountCompute.customProperties.get(EndpointAllocationTaskService.CUSTOM_PROP_ENPOINT_TYPE));
    computeState.customProperties.put(AWSConstants.ACCOUNT_IS_AUTO_DISCOVERED, Boolean.TRUE.toString());
    computeState.documentSelfLink = UriUtils.buildUriPath(ComputeService.FACTORY_LINK, computeState.id);
    computeState.endpointLink = primaryAccountCompute.endpointLink;
    if (computeState.endpointLinks == null) {
        computeState.endpointLinks = new HashSet<>();
    }
    computeState.endpointLinks.add(primaryAccountCompute.endpointLink);
    return computeState;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState)

Example 8 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestAWSEnumerationDocumentCountInLongRun method assertNetworkInterfaceLinksAreValid.

private void assertNetworkInterfaceLinksAreValid() {
    for (String computeLink : this.computeStateLinks) {
        Operation getCompute = Operation.createGet((UriUtils.buildUri(this.host, computeLink))).setReferer(this.host.getUri());
        Operation compute = this.host.waitForResponse(getCompute);
        if (compute.getStatusCode() == 200) {
            ComputeState state = compute.getBody(ComputeState.class);
            for (String nicLink : state.networkInterfaceLinks) {
                Operation getNic = Operation.createGet((UriUtils.buildUri(this.host, nicLink))).setReferer(this.host.getUri());
                Operation nic = this.host.waitForResponse(getNic);
                assertEquals("GET on NIC failed.", Operation.STATUS_CODE_OK, nic.getStatusCode());
            }
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Operation(com.vmware.xenon.common.Operation)

Example 9 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestAWSProvisionTask method assertVMSercurityGroupsConfiguration.

private void assertVMSercurityGroupsConfiguration(Instance instance, ComputeState vm) {
    // This assert is only suitable for real (non-mocking env).
    if (this.isMock) {
        return;
    }
    this.host.log(Level.INFO, "%s: Assert security groups configuration for [%s] VM", this.currentTestName.getMethodName(), this.vmState.name);
    // 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);
    // Compare ComputeState after provisioning to the ComputeState in the request
    assertNotNull("Instance should have security groups attached.", instance.getSecurityGroups());
    // Provisioned Instance should have the same number of SecurityGroups as requested
    assertEquals(instance.getSecurityGroups().size(), currentSGNamesToStates.size());
    for (SecurityGroupState currentSGState : currentSGNamesToStates.values()) {
        // Get corresponding requested state
        GroupIdentifier provisionedGroupIdentifier = null;
        for (GroupIdentifier awsGroupIdentifier : instance.getSecurityGroups()) {
            if (awsGroupIdentifier.getGroupId().equals(currentSGState.id)) {
                provisionedGroupIdentifier = awsGroupIdentifier;
                break;
            }
        }
        // Ensure that the requested SecurityGroup was actually provisioned
        assertNotNull(provisionedGroupIdentifier);
        if (currentSGState.name.contains(TestAWSSetupUtils.AWS_NEW_GROUP_PREFIX)) {
            this.sgToCleanUp = currentSGState.id;
            SecurityGroup awsSecurityGroup = getSecurityGroupsIdUsingEC2Client(this.client, provisionedGroupIdentifier.getGroupId());
            assertNotNull(awsSecurityGroup);
            // Validate rules are correctly created as requested
            IpPermission awsIngressRule = awsSecurityGroup.getIpPermissions().get(0);
            IpPermission awsEgressRule = awsSecurityGroup.getIpPermissionsEgress().get(1);
            assertNotNull(awsIngressRule);
            assertNotNull(awsEgressRule);
            assertEquals("Error in created ingress rule", awsIngressRule.getIpProtocol(), currentSGState.ingress.get(0).protocol);
            assertEquals("Error in created ingress rule", awsIngressRule.getIpv4Ranges().get(0).getCidrIp(), currentSGState.ingress.get(0).ipRangeCidr);
            assertEquals("Error in created egress rule", awsEgressRule.getIpProtocol(), currentSGState.egress.get(0).protocol);
            assertEquals("Error in created egress rule", awsEgressRule.getIpv4Ranges().get(0).getCidrIp(), currentSGState.egress.get(0).ipRangeCidr);
        }
    }
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) TestAWSSetupUtils.createAWSComputeHost(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSComputeHost) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) VerificationHost(com.vmware.xenon.common.test.VerificationHost) TestAWSSetupUtils.createAWSResourcePool(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSResourcePool) TestAWSSetupUtils.tearDownTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.tearDownTestVpc) DEVICE_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_NAME) TestAWSSetupUtils.setUpTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setUpTestVpc) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) AWSBlockDeviceNameMapper(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSBlockDeviceNameMapper) TestAWSSetupUtils.verifyRemovalOfResourceState(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.verifyRemovalOfResourceState) Map(java.util.Map) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier) After(org.junit.After) TestUtils.getExecutor(com.vmware.photon.controller.model.adapters.awsadapter.TestUtils.getExecutor) Collector(java.util.stream.Collector) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) AwsNicSpecs(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) AWS_VM_REQUEST_TIMEOUT_MINUTES(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AWS_VM_REQUEST_TIMEOUT_MINUTES) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) Collectors(java.util.stream.Collectors) VOLUME_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.VOLUME_TYPE) TestAWSSetupUtils.avalabilityZoneIdentifier(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.avalabilityZoneIdentifier) TestAWSSetupUtils.getSecurityGroupsIdUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getSecurityGroupsIdUsingEC2Client) List(java.util.List) TagService(com.vmware.photon.controller.model.resources.TagService) Tag(com.amazonaws.services.ec2.model.Tag) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) DiskService(com.vmware.photon.controller.model.resources.DiskService) SingleResourceTaskCollectionStage(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage) InstanceNetworkInterface(com.amazonaws.services.ec2.model.InstanceNetworkInterface) TestAWSSetupUtils.deleteSecurityGroupUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.deleteSecurityGroupUsingEC2Client) DISK_IOPS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DISK_IOPS) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) TestAWSSetupUtils.zoneId(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.zoneId) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) TestAWSSetupUtils.getAwsInstancesByIds(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getAwsInstancesByIds) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) InstanceBlockDeviceMapping(com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TestName(org.junit.rules.TestName) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) Volume(com.amazonaws.services.ec2.model.Volume) PLACEMENT_LINK(com.vmware.photon.controller.model.ComputeProperties.PLACEMENT_LINK) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) DEVICE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_TYPE) Instance(com.amazonaws.services.ec2.model.Instance) Before(org.junit.Before) TestAWSSetupUtils.createAWSAuthentication(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSAuthentication) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) TestAWSSetupUtils.getCompute(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getCompute) Test(org.junit.Test) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) TimeUnit(java.util.concurrent.TimeUnit) TestAWSSetupUtils.createAWSVMResource(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSVMResource) Rule(org.junit.Rule) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) TestAWSSetupUtils.regionId(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.regionId) TestAWSSetupUtils.setAwsClientMockInfo(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setAwsClientMockInfo) IpPermission(com.amazonaws.services.ec2.model.IpPermission) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) IpPermission(com.amazonaws.services.ec2.model.IpPermission) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) Map(java.util.Map) HashMap(java.util.HashMap) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier)

Example 10 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestAWSProvisionTask method testProvision.

// Creates a AWS instance via a provision task.
@Test
public void testProvision() throws Throwable {
    initResourcePoolAndComputeHost();
    // create a AWS VM compute resoruce
    boolean addNonExistingSecurityGroup = true;
    this.vmState = createAWSVMResource(this.host, this.computeHost, this.endpointState, this.getClass(), this.currentTestName.getMethodName() + "_vm1", zoneId, regionId, null, /* tagLinks */
    this.singleNicSpec, addNonExistingSecurityGroup, this.awsTestContext);
    // set placement link
    String zoneId = TestAWSSetupUtils.zoneId + avalabilityZoneIdentifier;
    ComputeState zoneComputeState = createAWSComputeHost(this.host, this.endpointState, zoneId, regionId, this.isAwsClientMock, this.awsMockEndpointReference, null);
    zoneComputeState.id = zoneId;
    zoneComputeState = TestUtils.doPatch(this.host, zoneComputeState, ComputeState.class, UriUtils.buildUri(this.host, zoneComputeState.documentSelfLink));
    if (this.vmState.customProperties == null) {
        this.vmState.customProperties = new HashMap<>();
    }
    this.vmState.customProperties.put(PLACEMENT_LINK, zoneComputeState.documentSelfLink);
    TestUtils.doPatch(this.host, this.vmState, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
    // kick off a provision task to do the actual VM creation
    ProvisionComputeTaskState provisionTask = new ProvisionComputeTaskService.ProvisionComputeTaskState();
    provisionTask.computeLink = this.vmState.documentSelfLink;
    provisionTask.isMockRequest = this.isMock;
    provisionTask.taskSubStage = ProvisionComputeTaskState.SubStage.CREATING_HOST;
    // Wait for default request timeout in minutes for the machine to be powered ON before
    // reporting failure to the parent task.
    provisionTask.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + TimeUnit.MINUTES.toMicros(AWS_VM_REQUEST_TIMEOUT_MINUTES);
    provisionTask.tenantLinks = this.endpointState.tenantLinks;
    provisionTask = TestUtils.doPost(this.host, provisionTask, ProvisionComputeTaskState.class, UriUtils.buildUri(this.host, ProvisionComputeTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(ProvisionComputeTaskState.class, provisionTask.documentSelfLink);
    // check that the VM has been created
    ProvisioningUtils.queryComputeInstances(this.host, 3);
    if (!this.isMock) {
        ComputeState compute = getCompute(this.host, this.vmState.documentSelfLink);
        List<Instance> instances = getAwsInstancesByIds(this.client, this.host, Collections.singletonList(compute.id));
        Instance instance = instances.get(0);
        assertTags(Collections.emptySet(), instance, this.vmState.name);
        assertVmNetworksConfiguration(instance);
        assertStorageConfiguration(this.client, instance, compute);
        assertEquals(zoneId, instance.getPlacement().getAvailabilityZone());
    }
    this.host.setTimeoutSeconds(600);
    this.host.waitFor("Error waiting for stats with default collection windows", () -> {
        try {
            this.host.log(Level.INFO, "Issuing stats request for VM with default collection window.");
            issueStatsRequest(this.vmState, null);
        } catch (Throwable t) {
            return false;
        }
        return true;
    });
    // store the network links and disk links for removal check later
    List<String> resourcesToDelete = new ArrayList<>();
    if (this.vmState.diskLinks != null) {
        resourcesToDelete.addAll(this.vmState.diskLinks);
    }
    if (this.vmState.networkInterfaceLinks != null) {
        resourcesToDelete.addAll(this.vmState.networkInterfaceLinks);
    }
    // delete vm
    TestAWSSetupUtils.deleteVMs(this.vmState.documentSelfLink, this.isMock, this.host);
    // validates the local documents of network links and disk links have been removed
    verifyRemovalOfResourceState(this.host, resourcesToDelete);
    // create another AWS VM
    List<String> instanceIdList = new ArrayList<>();
    Set<TagState> tags = createTags(null, "testProvisionKey1", "testProvisionValue1", "testProvisionKey2", "testProvisionValue2");
    Set<String> tagLinks = tags.stream().map(t -> t.documentSelfLink).collect(Collectors.toSet());
    addNonExistingSecurityGroup = false;
    this.vmState = createAWSVMResource(this.host, this.computeHost, this.endpointState, this.getClass(), this.currentTestName.getMethodName() + "_vm2", TestAWSSetupUtils.zoneId, regionId, tagLinks, this.singleNicSpec, addNonExistingSecurityGroup, this.awsTestContext);
    TestAWSSetupUtils.provisionMachine(this.host, this.vmState, this.isMock, instanceIdList);
    if (!this.isMock) {
        ComputeState compute = getCompute(this.host, this.vmState.documentSelfLink);
        List<Instance> instances = getAwsInstancesByIds(this.client, this.host, Collections.singletonList(compute.id));
        assertTags(tags, instances.get(0), this.vmState.name);
        assertVmNetworksConfiguration(instances.get(0));
        assertStorageConfiguration(this.client, instances.get(0), compute);
        // reach out to AWS and get the current state
        TestAWSSetupUtils.getBaseLineInstanceCount(this.host, this.client, null);
    }
    // delete just the local representation of the resource
    TestAWSSetupUtils.deleteVMs(this.vmState.documentSelfLink, this.isMock, this.host, true);
    if (!this.isMock) {
        try {
            TestAWSSetupUtils.getBaseLineInstanceCount(this.host, this.client, null);
        } finally {
            TestAWSSetupUtils.deleteVMsUsingEC2Client(this.client, this.host, instanceIdList);
            deleteSecurityGroupUsingEC2Client(this.client, this.host, this.sgToCleanUp);
        }
    }
    this.vmState = null;
    this.sgToCleanUp = null;
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) TestAWSSetupUtils.createAWSComputeHost(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSComputeHost) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) VerificationHost(com.vmware.xenon.common.test.VerificationHost) TestAWSSetupUtils.createAWSResourcePool(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSResourcePool) TestAWSSetupUtils.tearDownTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.tearDownTestVpc) DEVICE_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_NAME) TestAWSSetupUtils.setUpTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setUpTestVpc) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) AWSBlockDeviceNameMapper(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSBlockDeviceNameMapper) TestAWSSetupUtils.verifyRemovalOfResourceState(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.verifyRemovalOfResourceState) Map(java.util.Map) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier) After(org.junit.After) TestUtils.getExecutor(com.vmware.photon.controller.model.adapters.awsadapter.TestUtils.getExecutor) Collector(java.util.stream.Collector) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) AwsNicSpecs(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) AWS_VM_REQUEST_TIMEOUT_MINUTES(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AWS_VM_REQUEST_TIMEOUT_MINUTES) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) Collectors(java.util.stream.Collectors) VOLUME_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.VOLUME_TYPE) TestAWSSetupUtils.avalabilityZoneIdentifier(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.avalabilityZoneIdentifier) TestAWSSetupUtils.getSecurityGroupsIdUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getSecurityGroupsIdUsingEC2Client) List(java.util.List) TagService(com.vmware.photon.controller.model.resources.TagService) Tag(com.amazonaws.services.ec2.model.Tag) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) DiskService(com.vmware.photon.controller.model.resources.DiskService) SingleResourceTaskCollectionStage(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage) InstanceNetworkInterface(com.amazonaws.services.ec2.model.InstanceNetworkInterface) TestAWSSetupUtils.deleteSecurityGroupUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.deleteSecurityGroupUsingEC2Client) DISK_IOPS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DISK_IOPS) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) TestAWSSetupUtils.zoneId(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.zoneId) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) TestAWSSetupUtils.getAwsInstancesByIds(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getAwsInstancesByIds) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) InstanceBlockDeviceMapping(com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TestName(org.junit.rules.TestName) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) Volume(com.amazonaws.services.ec2.model.Volume) PLACEMENT_LINK(com.vmware.photon.controller.model.ComputeProperties.PLACEMENT_LINK) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) DEVICE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_TYPE) Instance(com.amazonaws.services.ec2.model.Instance) Before(org.junit.Before) TestAWSSetupUtils.createAWSAuthentication(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSAuthentication) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) TestAWSSetupUtils.getCompute(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getCompute) Test(org.junit.Test) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) TimeUnit(java.util.concurrent.TimeUnit) TestAWSSetupUtils.createAWSVMResource(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSVMResource) Rule(org.junit.Rule) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) TestAWSSetupUtils.regionId(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.regionId) TestAWSSetupUtils.setAwsClientMockInfo(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setAwsClientMockInfo) IpPermission(com.amazonaws.services.ec2.model.IpPermission) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Test(org.junit.Test)

Aggregations

ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)214 Operation (com.vmware.xenon.common.Operation)93 ArrayList (java.util.ArrayList)63 QueryTask (com.vmware.xenon.services.common.QueryTask)58 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)57 HashMap (java.util.HashMap)54 List (java.util.List)51 Map (java.util.Map)50 Utils (com.vmware.xenon.common.Utils)45 Test (org.junit.Test)45 UriUtils (com.vmware.xenon.common.UriUtils)44 URI (java.net.URI)42 Collectors (java.util.stream.Collectors)42 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)40 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)40 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)40 StatelessService (com.vmware.xenon.common.StatelessService)40 Query (com.vmware.xenon.services.common.QueryTask.Query)40 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)38 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)36