Search in sources :

Example 11 with EndpointState

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

the class ModelUtils method createCompute.

public static ComputeService.ComputeStateWithDescription createCompute(BaseModelTest test, ComputeDescriptionService.ComputeDescription cd) throws Throwable {
    ComputeService.ComputeState cs = new ComputeService.ComputeStateWithDescription();
    cs.id = UUID.randomUUID().toString();
    cs.name = cd.name;
    cs.descriptionLink = cd.documentSelfLink;
    cs.resourcePoolLink = null;
    cs.address = "10.0.0.1";
    cs.primaryMAC = "01:23:45:67:89:ab";
    cs.powerState = ComputeService.PowerState.ON;
    cs.adapterManagementReference = URI.create("https://esxhost-01:443/sdk");
    cs.diskLinks = new ArrayList<>();
    cs.diskLinks.add(createDiskState(test, cs.name).documentSelfLink);
    cs.networkInterfaceLinks = new ArrayList<>();
    EndpointState endpointState = createEndpoint(test);
    NetworkState networkState = createNetwork(test, endpointState);
    SubnetState subnetState = createSubnet(test, networkState, endpointState);
    SubnetRangeState subnetRangeState = createSubnetRange(test, subnetState, "12.12.12.2", "12.12.12.120");
    NetworkInterfaceState networkInterfaceState1 = createNetworkInterface(test, "nic-1", subnetState, networkState);
    IPAddressState ipAddressState1 = createIpAddress(test, "12.12.12.2", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState1.documentSelfLink);
    NetworkInterfaceState networkInterfaceState2 = createNetworkInterface(test, "nic-2", subnetState, networkState);
    IPAddressState ipAddressState2 = createIpAddress(test, "12.12.12.3", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState2.documentSelfLink);
    NetworkInterfaceState networkInterfaceState3 = createNetworkInterface(test, "nic-3", subnetState, networkState);
    IPAddressState ipAddressState3 = createIpAddress(test, "12.12.12.4", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState3.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState1.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState2.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState3.documentSelfLink);
    cs.customProperties = new HashMap<>();
    cs.customProperties.put(TEST_DESC_PROPERTY_NAME, TEST_DESC_PROPERTY_VALUE);
    cs.tenantLinks = new ArrayList<>();
    cs.tenantLinks.add("http://tenant");
    ComputeService.ComputeState returnState = test.postServiceSynchronously(ComputeService.FACTORY_LINK, cs, ComputeService.ComputeState.class);
    return ComputeService.ComputeStateWithDescription.create(cd, returnState);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SubnetRangeState(com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState) IPAddressState(com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 12 with EndpointState

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

the class EndpointAllocationTaskService method doTriggerEnumeration.

private void doTriggerEnumeration(EndpointAllocationTaskState currentState, SubStage next, URI adapterManagementReference) {
    EndpointState endpoint = currentState.endpointState;
    long intervalMicros = currentState.enumerationRequest.refreshIntervalMicros != null ? currentState.enumerationRequest.refreshIntervalMicros : DEFAULT_SCHEDULED_TASK_INTERVAL_MICROS;
    // Use endpoint documentSelfLink's last part as convention, so that we are able to stop
    // enumeration during endpoint update.
    String id = UriUtils.getLastPathSegment(endpoint.documentSelfLink);
    ResourceEnumerationTaskState enumTaskState = new ResourceEnumerationTaskState();
    enumTaskState.parentComputeLink = endpoint.computeLink;
    enumTaskState.endpointLink = endpoint.documentSelfLink;
    enumTaskState.resourcePoolLink = currentState.enumerationRequest.resourcePoolLink;
    enumTaskState.adapterManagementReference = adapterManagementReference;
    enumTaskState.tenantLinks = endpoint.tenantLinks;
    enumTaskState.options = EnumSet.of(TaskOption.SELF_DELETE_ON_COMPLETION);
    if (currentState.options.contains(TaskOption.IS_MOCK)) {
        enumTaskState.options.add(TaskOption.IS_MOCK);
    }
    if (currentState.options.contains(TaskOption.PRESERVE_MISSING_RESOUCES)) {
        enumTaskState.options.add(TaskOption.PRESERVE_MISSING_RESOUCES);
    }
    ScheduledTaskState scheduledTaskState = new ScheduledTaskState();
    scheduledTaskState.documentSelfLink = id;
    scheduledTaskState.factoryLink = ResourceEnumerationTaskService.FACTORY_LINK;
    scheduledTaskState.initialStateJson = Utils.toJson(enumTaskState);
    scheduledTaskState.intervalMicros = intervalMicros;
    scheduledTaskState.delayMicros = currentState.enumerationRequest.delayMicros;
    scheduledTaskState.noDelayOnInitialExecution = Boolean.TRUE;
    scheduledTaskState.tenantLinks = endpoint.tenantLinks;
    scheduledTaskState.customProperties = new HashMap<>();
    scheduledTaskState.customProperties.put(ENDPOINT_LINK_PROP_NAME, endpoint.documentSelfLink);
    Operation.createPost(this, ScheduledTaskService.FACTORY_LINK).addPragmaDirective(Operation.PRAGMA_DIRECTIVE_FORCE_INDEX_UPDATE).setBody(scheduledTaskState).setCompletion((o, e) -> {
        if (e != null) {
            logWarning(() -> String.format("Error triggering Enumeration task, reason:" + " %s", e.getMessage()));
        }
        sendSelfPatch(createUpdateSubStageTask(next));
    }).sendWith(this);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Map(java.util.Map) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ENDPOINT_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PhotonModelAdaptersConfigAccessService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) TaskUtils.sendFailurePatch(com.vmware.photon.controller.model.tasks.TaskUtils.sendFailurePatch) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) AdapterTypePath(com.vmware.photon.controller.model.UriPaths.AdapterTypePath) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OperationSequence(com.vmware.xenon.common.OperationSequence) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) CertificateInfo(com.vmware.photon.controller.model.support.CertificateInfo) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState)

Example 13 with EndpointState

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

the class EndpointAllocationTaskService method createEndpoint.

private void createEndpoint(EndpointAllocationTaskState currentState) {
    List<String> createdDocumentLinks = new ArrayList<>();
    EndpointState es = currentState.endpointState;
    Map<String, String> endpointProperties = currentState.endpointState.endpointProperties;
    es.endpointProperties = null;
    if (es.documentSelfLink == null) {
        es.documentSelfLink = UriUtils.buildUriPath(EndpointService.FACTORY_LINK, this.getHost().nextUUID());
    }
    // merge endpoint and task tenant links
    if (es.tenantLinks == null || es.tenantLinks.isEmpty()) {
        es.tenantLinks = currentState.tenantLinks;
    } else if (currentState.tenantLinks != null) {
        currentState.tenantLinks.forEach(tl -> {
            if (!es.tenantLinks.contains(tl)) {
                es.tenantLinks.add(tl);
            }
        });
    }
    Operation endpointOp = Operation.createPost(this, EndpointService.FACTORY_LINK);
    ComputeDescription computeDescription = configureDescription(currentState, es);
    ComputeState computeState = configureCompute(currentState, es, endpointProperties);
    Operation cdOp = createComputeDescriptionOp(currentState, computeDescription.documentSelfLink);
    Operation compOp = createComputeStateOp(currentState, computeState.documentSelfLink);
    // pool link
    if (currentState.enumerationRequest != null && currentState.enumerationRequest.resourcePoolLink != null) {
        es.resourcePoolLink = currentState.enumerationRequest.resourcePoolLink;
        computeState.resourcePoolLink = es.resourcePoolLink;
    }
    OperationSequence sequence;
    if (es.authCredentialsLink == null) {
        AuthCredentialsServiceState auth = configureAuth(es);
        Operation authOp = Operation.createPost(createInventoryUri(this.getHost(), AuthCredentialsService.FACTORY_LINK)).setBody(auth);
        sequence = OperationSequence.create(authOp).setCompletion((ops, exs) -> {
            if (exs != null) {
                long firstKey = exs.keySet().iterator().next();
                exs.values().forEach(ex -> logWarning(() -> String.format("Error in " + "sequence to create auth credentials: %s", ex.getMessage())));
                sendFailurePatch(this, currentState, exs.get(firstKey));
                return;
            }
            Operation o = ops.get(authOp.getId());
            AuthCredentialsServiceState authState = o.getBody(AuthCredentialsServiceState.class);
            computeDescription.authCredentialsLink = authState.documentSelfLink;
            es.authCredentialsLink = authState.documentSelfLink;
            cdOp.setBody(computeDescription);
        }).next(cdOp);
    } else {
        cdOp.setBody(computeDescription);
        sequence = OperationSequence.create(cdOp);
    }
    sequence = sequence.setCompletion((ops, exs) -> {
        if (exs != null) {
            long firstKey = exs.keySet().iterator().next();
            exs.values().forEach(ex -> logWarning(() -> String.format("Error in " + "sequence to create compute description: %s", ex.getMessage())));
            sendFailurePatch(this, currentState, exs.get(firstKey));
            return;
        }
        Operation o = ops.get(cdOp.getId());
        ComputeDescription desc = o.getBody(ComputeDescription.class);
        if (!currentState.accountAlreadyExists) {
            createdDocumentLinks.add(desc.documentSelfLink);
        }
        computeState.descriptionLink = desc.documentSelfLink;
        es.computeDescriptionLink = desc.documentSelfLink;
    });
    // Don't create resource pool, if a resource pool link was passed.
    if (es.resourcePoolLink == null) {
        Operation poolOp = createResourcePoolOp(es);
        sequence = sequence.next(poolOp).setCompletion((ops, exs) -> {
            if (exs != null) {
                long firstKey = exs.keySet().iterator().next();
                exs.values().forEach(ex -> logWarning(() -> String.format("Error creating resource" + " pool: %s", ex.getMessage())));
                sendFailurePatch(this, currentState, exs.get(firstKey));
                return;
            }
            Operation o = ops.get(poolOp.getId());
            ResourcePoolState poolState = o.getBody(ResourcePoolState.class);
            createdDocumentLinks.add(poolState.documentSelfLink);
            es.resourcePoolLink = poolState.documentSelfLink;
            computeState.resourcePoolLink = es.resourcePoolLink;
            compOp.setBody(computeState);
        });
    } else {
        Operation getPoolOp = Operation.createGet(this, es.resourcePoolLink);
        sequence = sequence.next(getPoolOp).setCompletion((ops, exs) -> {
            if (exs != null) {
                long firstKey = exs.keySet().iterator().next();
                exs.values().forEach(ex -> logWarning(() -> String.format("Error retrieving resource" + " pool: %s", ex.getMessage())));
                sendFailurePatch(this, currentState, exs.get(firstKey));
                return;
            }
            Operation o = ops.get(getPoolOp.getId());
            ResourcePoolState poolState = o.getBody(ResourcePoolState.class);
            if (poolState.customProperties != null) {
                String endpointLink = poolState.customProperties.get(ENDPOINT_LINK_PROP_NAME);
                if (endpointLink != null && endpointLink.equals(es.documentSelfLink)) {
                    sendFailurePatch(this, currentState, new IllegalStateException("Passed resource pool is associated with a different endpoint."));
                    return;
                }
            }
            es.resourcePoolLink = poolState.documentSelfLink;
            computeState.resourcePoolLink = es.resourcePoolLink;
            compOp.setBody(computeState);
        });
    }
    sequence.next(compOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            long firstKey = exs.keySet().iterator().next();
            exs.values().forEach(ex -> logWarning(() -> String.format("Error in " + "sequence to create compute state: %s", ex.getMessage())));
            sendFailurePatch(this, currentState, exs.get(firstKey));
            return;
        }
        Operation csOp = ops.get(compOp.getId());
        ComputeState c = csOp.getBody(ComputeState.class);
        if (!currentState.accountAlreadyExists) {
            createdDocumentLinks.add(c.documentSelfLink);
        }
        es.computeLink = c.documentSelfLink;
        endpointOp.setBody(es);
    }).next(endpointOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            long firstKey = exs.keySet().iterator().next();
            exs.values().forEach(ex -> logWarning(() -> String.format("Error in " + "sequence to create endpoint state: %s", ex.getMessage())));
            sendFailurePatch(this, currentState, exs.get(firstKey));
            return;
        }
        Operation esOp = ops.get(endpointOp.getId());
        EndpointState endpoint = esOp.getBody(EndpointState.class);
        createdDocumentLinks.add(endpoint.documentSelfLink);
        // propagate the endpoint properties to the next stage
        endpoint.endpointProperties = endpointProperties;
        EndpointAllocationTaskState state = createUpdateSubStageTask(SubStage.INVOKE_ADAPTER);
        state.endpointState = endpoint;
        state.createdDocumentLinks = createdDocumentLinks;
        sendSelfPatch(state);
    }).sendWith(this);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Map(java.util.Map) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ENDPOINT_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PhotonModelAdaptersConfigAccessService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) TaskUtils.sendFailurePatch(com.vmware.photon.controller.model.tasks.TaskUtils.sendFailurePatch) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) AdapterTypePath(com.vmware.photon.controller.model.UriPaths.AdapterTypePath) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OperationSequence(com.vmware.xenon.common.OperationSequence) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) CertificateInfo(com.vmware.photon.controller.model.support.CertificateInfo) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) OperationSequence(com.vmware.xenon.common.OperationSequence) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 14 with EndpointState

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

the class EndpointRemovalTaskService method doInstanceDelete.

/**
 * Delete endpoint
 */
private void doInstanceDelete(EndpointRemovalTaskState currentState, SubStage next) {
    EndpointState endpoint = currentState.endpoint;
    Operation crdOp = Operation.createDelete(createInventoryUri(this.getHost(), endpoint.authCredentialsLink));
    Operation epOp = Operation.createDelete(createInventoryUri(this.getHost(), endpoint.documentSelfLink));
    // custom header identifier for endpoint service to validate before deleting endpoint
    epOp.addRequestHeader(ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME, ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE);
    OperationJoin.create(crdOp, epOp).setCompletion((ops, exc) -> {
        if (exc != null) {
            // failing to delete the endpoint itself is considered a critical error
            Throwable endpointRemovalException = exc.get(epOp.getId());
            if (endpointRemovalException != null) {
                sendFailureSelfPatch(endpointRemovalException);
                return;
            }
            // other removal exceptions are just warnings
            logFine(() -> String.format("Failed delete some of the associated resources," + " reason %s", Utils.toString(exc)));
        }
        // Endpoint and AuthCredentials are deleted; mark the operation as complete
        sendSelfPatch(TaskStage.STARTED, next);
    }).sendWith(this);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) LINK(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.LINK) Service(com.vmware.xenon.common.Service) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) QueryTask(com.vmware.xenon.services.common.QueryTask) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Utils(com.vmware.xenon.common.Utils) RouterState(com.vmware.photon.controller.model.resources.RouterService.RouterState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) SEPARATOR(com.vmware.photon.controller.model.tasks.monitoring.StatsUtil.SEPARATOR) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) Collection(java.util.Collection) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) ServiceHost(com.vmware.xenon.common.ServiceHost) ENDPOINT_LINK_EXPLICIT_SUPPORT(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.ENDPOINT_LINK_EXPLICIT_SUPPORT) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) UriUtils(com.vmware.xenon.common.UriUtils) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) ArrayList(java.util.ArrayList) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE(com.vmware.photon.controller.model.resources.EndpointService.ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE) ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME(com.vmware.photon.controller.model.resources.EndpointService.ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) Operation(com.vmware.xenon.common.Operation)

Example 15 with EndpointState

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

the class EndpointRemovalTaskServiceTest method createEndpoint.

private static EndpointState createEndpoint(BaseModelTest test) throws Throwable {
    EndpointState endpoint = createEndpointState();
    // Create endpoint
    EndpointAllocationTaskState startState = createEndpointAllocationRequest(endpoint);
    startState.adapterReference = UriUtils.buildUri(test.getHost(), MockSuccessEndpointAdapter.SELF_LINK);
    EndpointAllocationTaskState returnState = test.postServiceSynchronously(EndpointAllocationTaskService.FACTORY_LINK, startState, EndpointAllocationTaskState.class);
    EndpointAllocationTaskState completeState = test.waitForServiceState(EndpointAllocationTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage.ordinal());
    assertThat(completeState.taskInfo.stage, is(TaskState.TaskStage.FINISHED));
    EndpointAllocationTaskState taskState = getServiceSynchronously(test, completeState.documentSelfLink, EndpointAllocationTaskState.class);
    assertNotNull(taskState);
    assertNotNull(taskState.endpointState);
    ServiceDocument endpointState = taskState.endpointState;
    assertNotNull(endpointState.documentSelfLink);
    return getServiceSynchronously(test, endpointState.documentSelfLink, EndpointState.class);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument)

Aggregations

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)69 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)23 Operation (com.vmware.xenon.common.Operation)22 Test (org.junit.Test)16 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)13 URI (java.net.URI)13 HashMap (java.util.HashMap)13 Query (com.vmware.xenon.services.common.QueryTask.Query)12 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 List (java.util.List)11 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)10 ServiceDocument (com.vmware.xenon.common.ServiceDocument)10 Collectors (java.util.stream.Collectors)10 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9