Search in sources :

Example 1 with ResourceEnumerationTaskState

use of com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState 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 2 with ResourceEnumerationTaskState

use of com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState in project photon-model by vmware.

the class TestAzureEnumerationTask method runEnumeration.

private void runEnumeration() throws Throwable {
    ResourceEnumerationTaskState enumerationTaskState = new ResourceEnumerationTaskState();
    enumerationTaskState.endpointLink = endpointState.documentSelfLink;
    enumerationTaskState.tenantLinks = endpointState.tenantLinks;
    enumerationTaskState.parentComputeLink = computeHost.documentSelfLink;
    enumerationTaskState.enumerationAction = EnumerationAction.START;
    enumerationTaskState.adapterManagementReference = UriUtils.buildUri(AzureEnumerationAdapterService.SELF_LINK);
    enumerationTaskState.resourcePoolLink = computeHost.resourcePoolLink;
    if (this.isMock) {
        enumerationTaskState.options = EnumSet.of(TaskOption.IS_MOCK);
    }
    ResourceEnumerationTaskState enumTask = TestUtils.doPost(this.host, enumerationTaskState, ResourceEnumerationTaskState.class, UriUtils.buildUri(this.host, ResourceEnumerationTaskService.FACTORY_LINK));
    this.host.waitFor("Error waiting for enumeration task", () -> {
        try {
            ResourceEnumerationTaskState state = this.host.waitForFinishedTask(ResourceEnumerationTaskState.class, enumTask.documentSelfLink);
            if (state != null) {
                return true;
            }
        } catch (Throwable e) {
            return false;
        }
        return false;
    });
}
Also used : ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState)

Example 3 with ResourceEnumerationTaskState

use of com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState in project photon-model by vmware.

the class TestGCPStatsCollection method runEnumeration.

/**
 * Run the enumeration and wait until it ends.
 * @throws Throwable Exception during running and waiting enumeration.
 */
private void runEnumeration() throws Throwable {
    ResourceEnumerationTaskState enumTask = createResourceEnumerationTask(this.outPool.documentSelfLink, this.computeHost.documentSelfLink, GCPEnumerationAdapterService.SELF_LINK, this.isMock, this.computeHost.tenantLinks);
    ResourceEnumerationTaskState enumTaskState = performResourceEnumeration(this.host, null, enumTask);
    this.host.waitForFinishedTask(ResourceEnumerationTaskState.class, enumTaskState.documentSelfLink);
}
Also used : ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState)

Example 4 with ResourceEnumerationTaskState

use of com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState in project photon-model by vmware.

the class BaseVSphereAdapterTest method enumerateComputes.

protected void enumerateComputes(ComputeState computeHost, EndpointState endpointState, EnumSet<TaskOption> options) throws Throwable {
    ResourceEnumerationTaskState task = new ResourceEnumerationTaskState();
    task.adapterManagementReference = computeHost.adapterManagementReference;
    task.enumerationAction = EnumerationAction.REFRESH;
    task.parentComputeLink = computeHost.documentSelfLink;
    task.resourcePoolLink = this.resourcePool.documentSelfLink;
    if (endpointState != null) {
        task.endpointLink = endpointState.documentSelfLink;
    } else {
        task.endpointLink = "/some/endpoint/link";
    }
    task.options = options;
    if (isMock()) {
        if (task.options == null) {
            task.options = EnumSet.of(TaskOption.IS_MOCK);
        } else {
            task.options.add(TaskOption.IS_MOCK);
        }
    }
    ResourceEnumerationTaskState outTask = TestUtils.doPost(this.host, task, ResourceEnumerationTaskState.class, UriUtils.buildUri(this.host, ResourceEnumerationTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(ResourceEnumerationTaskState.class, outTask.documentSelfLink);
}
Also used : ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState)

Example 5 with ResourceEnumerationTaskState

use of com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState in project photon-model by vmware.

the class AzureTestUtil method runEnumeration.

/**
 * Runs azure enumeration.
 */
public static void runEnumeration(VerificationHost host, String hostSelfLink, String resourcePoolLink, EndpointState endpointState, boolean isMock) throws Throwable {
    ResourceEnumerationTaskState enumerationTaskState = new ResourceEnumerationTaskState();
    enumerationTaskState.endpointLink = endpointState.documentSelfLink;
    enumerationTaskState.tenantLinks = endpointState.tenantLinks;
    enumerationTaskState.parentComputeLink = hostSelfLink;
    enumerationTaskState.enumerationAction = EnumerationAction.START;
    enumerationTaskState.adapterManagementReference = UriUtils.buildUri(AzureEnumerationAdapterService.SELF_LINK);
    enumerationTaskState.resourcePoolLink = resourcePoolLink;
    if (isMock) {
        enumerationTaskState.options = EnumSet.of(TaskOption.IS_MOCK);
    }
    ResourceEnumerationTaskState enumTask = TestUtils.doPost(host, enumerationTaskState, ResourceEnumerationTaskState.class, UriUtils.buildUri(host, ResourceEnumerationTaskService.FACTORY_LINK));
    host.waitFor("Error waiting for enumeration task", () -> {
        try {
            ResourceEnumerationTaskState state = host.waitForFinishedTask(ResourceEnumerationTaskState.class, enumTask.documentSelfLink);
            if (state != null) {
                return true;
            }
        } catch (Throwable e) {
            return false;
        }
        return false;
    });
}
Also used : ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState)

Aggregations

ResourceEnumerationTaskState (com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState)10 ENDPOINT_LINK_PROP_NAME (com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME)1 UriPaths (com.vmware.photon.controller.model.UriPaths)1 AdapterTypePath (com.vmware.photon.controller.model.UriPaths.AdapterTypePath)1 EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)1 RequestType (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType)1 PhotonModelAdaptersConfigAccessService (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService)1 PhotonModelAdapterConfig (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)1 CUSTOM_PROP_ENDPOINT_LINK (com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK)1 SOURCE_TASK_LINK (com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK)1 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)1 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)1 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 EndpointService (com.vmware.photon.controller.model.resources.EndpointService)1 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)1 ResourcePoolService (com.vmware.photon.controller.model.resources.ResourcePoolService)1 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)1 CertificateInfo (com.vmware.photon.controller.model.support.CertificateInfo)1 CertificateInfoServiceErrorResponse (com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse)1