Search in sources :

Example 6 with ResourceState

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

the class EndpointEnumerationProcess method createUpdateLocalResourceState.

protected DeferredResult<Operation> createUpdateLocalResourceState(LocalStateHolder localStateHolder) {
    final ResourceState localState = localStateHolder.localState;
    if (localState == this.SKIP) {
        return DeferredResult.completed(null);
    }
    final LOCAL_STATE currentState = this.localResourceStates.get(localState.id);
    // POST or PATCH local state
    final Operation localStateOp;
    if (currentState == null) {
        if (localState.regionId == null) {
            // By default populate REGION_ID, if not already set by descendant
            localState.regionId = getEndpointRegion();
        }
        if (isApplyInfraFields()) {
            // By default populate TENANT_LINKS
            localState.tenantLinks = this.endpointState.tenantLinks;
            // By default populate ENDPOINT_LINK
            setEndpointLink(localState, this.endpointState.documentSelfLink);
            updateEndpointLinks(localState, this.endpointState.documentSelfLink);
        }
        localState.computeHostLink = this.computeHostLink;
        localStateOp = Operation.createPost(createInventoryUri(this.service.getHost(), this.localStateServiceFactoryLink));
    } else {
        // Update case
        if (isApplyInfraFields()) {
            setEndpointLink(localState, this.endpointState.documentSelfLink);
            // update the endpointLinks
            updateEndpointLinks(localState, this.endpointState.documentSelfLink);
        }
        localStateOp = Operation.createPatch(createInventoryUri(this.service.getHost(), currentState.documentSelfLink));
    }
    DeferredResult<Set<String>> tagLinksDR = TagsUtil.createOrUpdateTagStates(this.service, localState, currentState, localStateHolder.remoteTags, localStateHolder.internalTagLinks);
    return tagLinksDR.thenApply(tagLinks -> {
        localState.tagLinks = tagLinks;
        localStateOp.setBodyNoCloning(localState);
        return localStateOp;
    }).thenCompose(this.service::sendWithDeferredResult).whenComplete((ignoreOp, exc) -> {
        String msg = "%s local %s(id=%s) to match remote resources";
        if (exc != null) {
            this.service.logWarning(() -> String.format(msg + ": FAILED with %s", localStateOp.getAction(), localState.getClass().getSimpleName(), localState.id, Utils.toString(exc)));
        } else {
            this.service.log(Level.FINEST, () -> String.format(msg + ": SUCCESS", localStateOp.getAction(), localState.getClass().getSimpleName(), localState.id));
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation)

Example 7 with ResourceState

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

the class AdapterUtils method getDeletionState.

public static ResourceState getDeletionState(long documentExpirationMicros) {
    ResourceState resourceState = new ResourceState();
    resourceState.documentExpirationTimeMicros = documentExpirationMicros;
    return resourceState;
}
Also used : ResourceState(com.vmware.photon.controller.model.resources.ResourceState)

Example 8 with ResourceState

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

the class TestAWSSetupUtils method verifyRemovalOfResourceState.

/**
 * Validates the documents of ResourceState have been removed.
 *
 * @throws Throwable
 */
public static void verifyRemovalOfResourceState(VerificationHost host, List<String> resourceStateLinks) throws Throwable {
    for (String resourceLink : resourceStateLinks) {
        ResourceState resourceState = getResourceState(host, resourceLink);
        assertNotNull(resourceState);
        // make sure the document has been removed.
        assertNull(resourceState.documentSelfLink);
    }
}
Also used : ResourceState(com.vmware.photon.controller.model.resources.ResourceState)

Example 9 with ResourceState

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

the class AzureTestUtil method verifyRemovalOfResourceState.

/**
 * Validate the deletion of documents of ResourceState.
 */
public static void verifyRemovalOfResourceState(VerificationHost host, List<String> resourceStateLinks) throws Throwable {
    for (String resourceLink : resourceStateLinks) {
        ResourceState resourceState = getResourceState(host, resourceLink);
        assertNotNull(resourceState);
        // make sure the document has been removed.
        assertNull(resourceState.documentSelfLink);
    }
}
Also used : ResourceState(com.vmware.photon.controller.model.resources.ResourceState)

Example 10 with ResourceState

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

the class TestAzureLongRunningEnumeration method verifyResourceDuplicates.

/**
 * Verify documents for duplicates after multiple enumerations.
 */
private void verifyResourceDuplicates() {
    int total_dup_resource_count = 0;
    for (Class resource : resourcesList) {
        QueryTask.Query.Builder qBuilder = QueryTask.Query.Builder.create().addKindFieldClause(resource).addFieldClause("endpointLinks.item", this.endpointState.documentSelfLink, QueryTask.QueryTerm.MatchType.TERM, QueryTask.Query.Occurance.MUST_OCCUR);
        if (resource.getSimpleName().equals("ComputeState")) {
            qBuilder.addFieldClause("type", "VM_GUEST", QueryTask.QueryTerm.MatchType.TERM, QueryTask.Query.Occurance.MUST_OCCUR);
        }
        QueryTask resourceQt = QueryTask.Builder.createDirectTask().setQuery(qBuilder.build()).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).addOption(QueryTask.QuerySpecification.QueryOption.TOP_RESULTS).setResultLimit(10000).build();
        Operation queryDocuments = QueryUtils.createQueryTaskOperation(this.host, resourceQt, ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE).setReferer(this.host.getUri());
        Operation queryResponse = this.host.waitForResponse(queryDocuments);
        Assert.assertTrue("Error retrieving enumerated documents", queryResponse.getStatusCode() == 200);
        QueryTask qt = queryResponse.getBody(QueryTask.class);
        Set<String> resourceIdSet = new HashSet<>();
        if (qt.results != null && qt.results.documentLinks != null && qt.results.documentLinks.size() > 0) {
            this.host.log("Number of %s docs: %d", resource.getSimpleName(), qt.results.documentLinks.size());
            for (String resourceDocumentLink : qt.results.documentLinks) {
                Object object = qt.results.documents.get(resourceDocumentLink);
                ResourceState resourceState = Utils.fromJson(object, ResourceState.class);
                String resourceId = resourceState.id;
                if (!resourceIdSet.contains(resourceId)) {
                    resourceIdSet.add(resourceId);
                } else {
                    this.host.log("duplicate %s id = %s, with state: ", resource.getSimpleName(), resourceId, Utils.toJsonHtml(resourceState));
                    total_dup_resource_count++;
                }
            }
        }
    }
    assertEquals("Duplicate resources found: ", 0, total_dup_resource_count);
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) PhotonModelUtils.createOriginTagQuery(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.createOriginTagQuery) BeforeClass(org.junit.BeforeClass) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) AzureTestUtil.randomString(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString) HashSet(java.util.HashSet)

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