Search in sources :

Example 11 with ResourceState

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

the class TestAWSEnumerationTask method markFirstResourceStateAsStale.

/**
 * From all the particular resource states, gets the first one, and patch it with an id, which
 * do not correspond to any actually existing resource
 * on the cloud, in order to test that this resource state will be deleted after the next enumeration run.
 */
private String markFirstResourceStateAsStale(VerificationHost host, Class<? extends ResourceState> resourceClass, String serviceFactoryLink) throws Throwable {
    // get enumerated resources, and change the id of one of them, so that it is deleted on the
    // next enum
    Map<String, ? extends ResourceState> statesMap = ProvisioningUtils.getResourceStates(host, serviceFactoryLink, resourceClass);
    assertNotNull("There should be resources enumerated.", statesMap);
    assertFalse("There should be resources enumerated.", statesMap.isEmpty());
    ResourceState existingState = statesMap.values().iterator().next();
    existingState.id = existingState.id + "-stale";
    existingState = doPatch(host, existingState, resourceClass, UriUtils.buildUri(host, existingState.documentSelfLink));
    return existingState.documentSelfLink;
}
Also used : ResourceState(com.vmware.photon.controller.model.resources.ResourceState)

Example 12 with ResourceState

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

the class TestAWSEnumerationTask method validateTagInEntity.

/**
 * Validates that the given internal tag is present on the passed in entity.
 */
private void validateTagInEntity(ServiceDocumentQueryResult queryResult, Class<?> documentKind, String internalTagType) {
    ServiceDocumentQueryResult tagsResult;
    String tagLink;
    tagsResult = getInternalTagsByType(this.host, internalTagType);
    assertEquals(count1, tagsResult.documentLinks.size());
    tagLink = tagsResult.documentLinks.get(0);
    for (Map.Entry<String, Object> resourceMap : queryResult.documents.entrySet()) {
        if (documentKind == ComputeState.class) {
            ComputeState compute = Utils.fromJson(resourceMap.getValue(), ComputeState.class);
            if (!compute.type.equals(ComputeType.ZONE) && !compute.type.equals(ComputeType.ENDPOINT_HOST)) {
                assertTrue(compute.tagLinks.contains(tagLink));
            }
        } else {
            ResourceState resourceState = Utils.fromJson(resourceMap.getValue(), ResourceState.class);
            if (resourceState.tagLinks != null) {
                assertTrue(resourceState.tagLinks.contains(tagLink));
            }
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Map(java.util.Map) HashMap(java.util.HashMap) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 13 with ResourceState

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

the class TestAWSEnumerationTask method validateStaleResourceStateDeletion.

private void validateStaleResourceStateDeletion(String... staleResourceSelfLinks) throws Throwable {
    for (String selfLink : staleResourceSelfLinks) {
        ResourceState resourceState = null;
        try {
            resourceState = host.getServiceState(null, ResourceState.class, UriUtils.buildUri(this.host, selfLink));
        } catch (Throwable e) {
        // do nothing, expected is the resource not to be found
        }
        // the resourceState will be deleted by the groomer task after disassociation
        assertTrue("Stale subnet state should have been disassociated.", resourceState.endpointLinks.isEmpty());
    }
}
Also used : ResourceState(com.vmware.photon.controller.model.resources.ResourceState)

Aggregations

ResourceState (com.vmware.photon.controller.model.resources.ResourceState)13 Operation (com.vmware.xenon.common.Operation)4 HashSet (java.util.HashSet)4 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)3 QueryTask (com.vmware.xenon.services.common.QueryTask)3 ServiceDocument (com.vmware.xenon.common.ServiceDocument)2 Set (java.util.Set)2 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)1 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 DescribeInternetGatewaysRequest (com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest)1 DescribeInternetGatewaysResult (com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult)1 DescribeRouteTablesRequest (com.amazonaws.services.ec2.model.DescribeRouteTablesRequest)1 DescribeRouteTablesResult (com.amazonaws.services.ec2.model.DescribeRouteTablesResult)1 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)1 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)1 DescribeVpcsRequest (com.amazonaws.services.ec2.model.DescribeVpcsRequest)1 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)1 Filter (com.amazonaws.services.ec2.model.Filter)1 InternetGateway (com.amazonaws.services.ec2.model.InternetGateway)1 InternetGatewayAttachment (com.amazonaws.services.ec2.model.InternetGatewayAttachment)1