Search in sources :

Example 1 with EndpointType

use of com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType in project photon-model by vmware.

the class EndpointAdapterUtils method registerEndpointAdapters.

/**
 * Register end-point adapters into End-point Adapters Registry.
 *
 * @param host
 *         The host the end-point is running on.
 * @param endpointType
 *         The type of the end-point.
 * @param startedAdapterLinks
 *         The array of started adapter links.
 * @param adapterLinksToRegister
 *         Map of adapter links (to be registered) to their adapter type key. e.g for
 *         standard adapters this is {@link com.vmware.photon.controller.model.UriPaths.AdapterTypePath#key}
 * @param registryLocator
 *         ServiceEndpointLocator containing the host of the adapter registry. Can be null if the
 *         registry is on the same host.
 * @see #handleEndpointRegistration(ServiceHost, EndpointType, Consumer, ServiceEndpointLocator)
 */
public static void registerEndpointAdapters(ServiceHost host, EndpointType endpointType, String[] startedAdapterLinks, Map<String, String> adapterLinksToRegister, ServiceEndpointLocator registryLocator) {
    // Count all adapters - both FAILED and STARTED
    AtomicInteger adaptersCountDown = new AtomicInteger(startedAdapterLinks.length);
    // Keep started adapters only...
    // - key = adapter type ket (e.g. AdapterTypePath.key)
    // - value = adapter URI
    Map<String, String> startedAdapters = new ConcurrentHashMap<>();
    // Wait for all adapter services to start
    host.registerForServiceAvailability((op, ex) -> {
        if (ex != null) {
            String adapterPath = op.getUri().getPath();
            host.log(Level.WARNING, "Starting '%s' adapter [%s]: FAILED - %s", endpointType, adapterPath, Utils.toString(ex));
        } else {
            String adapterPath = op.getUri().getPath();
            host.log(Level.FINE, "Starting '%s' adapter [%s]: SUCCESS", endpointType, adapterPath);
            String adapterKey = adapterLinksToRegister.get(adapterPath);
            if (adapterKey != null) {
                startedAdapters.put(adapterKey, AdapterUriUtil.buildPublicAdapterUri(host, adapterPath).toString());
            }
        }
        if (adaptersCountDown.decrementAndGet() == 0) {
            // Once ALL Adapters are started register them into End-point Adapters Registry
            host.log(Level.INFO, "Starting %d '%s' adapters: SUCCESS", startedAdapters.size(), endpointType);
            // Populate end-point config with started adapters
            Consumer<PhotonModelAdapterConfig> endpointConfigEnhancer = ep -> ep.adapterEndpoints.putAll(startedAdapters);
            // Delegate to core end-point config/registration logic
            handleEndpointRegistration(host, endpointType, endpointConfigEnhancer, registryLocator);
        }
    }, /* this services are not replicated */
    false, startedAdapterLinks);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) HashMap(java.util.HashMap) ServiceEndpointLocator(com.vmware.photon.controller.model.util.ServiceEndpointLocator) Level(java.util.logging.Level) Utils(com.vmware.xenon.common.Utils) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) INVENTORY_SERVICE(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) Consumer(java.util.function.Consumer) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) Stream(java.util.stream.Stream) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils.buildUri(com.vmware.xenon.common.UriUtils.buildUri) Optional(java.util.Optional) PhotonModelAdaptersRegistryService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)

Example 2 with EndpointType

use of com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType in project photon-model by vmware.

the class AWSInstanceTypeServiceTest method createEndpointState.

private EndpointState createEndpointState() throws Throwable {
    EndpointType endpointType = EndpointType.aws;
    EndpointState endpoint;
    {
        endpoint = new EndpointState();
        endpoint.endpointType = endpointType.name();
        endpoint.id = endpointType.name() + "-id";
        endpoint.name = endpointType.name() + "-name";
        endpoint.endpointProperties = new HashMap<>();
        endpoint.endpointProperties.put(PRIVATE_KEY_KEY, this.secretKey);
        endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, this.accessKey);
        endpoint.endpointProperties.put(REGION_KEY, Regions.US_EAST_1.getName());
    }
    EndpointAllocationTaskState allocateEndpoint = new EndpointAllocationTaskState();
    allocateEndpoint.endpointState = endpoint;
    allocateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
    allocateEndpoint.taskInfo = new TaskState();
    allocateEndpoint.taskInfo.isDirect = true;
    allocateEndpoint.tenantLinks = Collections.singletonList(endpointType.name() + "-tenant");
    allocateEndpoint = com.vmware.photon.controller.model.tasks.TestUtils.doPost(this.host, allocateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    return allocateEndpoint.endpointState;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) HashMap(java.util.HashMap) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) TaskState(com.vmware.xenon.common.TaskState)

Example 3 with EndpointType

use of com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType in project photon-model by vmware.

the class TestAzureImageEnumerationTask method testPublicImageEnumeration_singleAndDefaults.

@Test
public void testPublicImageEnumeration_singleAndDefaults() throws Throwable {
    // Important: MUST share same Endpoint between the two enum runs.
    ServiceDocumentQueryResult imagesAfterFirstEnum = null;
    ImageState imageAfterFirstEnum = null;
    ServiceDocumentQueryResult imagesAfterSecondEnum = null;
    final Function<Collection<Object>, ImageState> imageFinder = collection -> collection.stream().map(imageStateAsObj -> Utils.fromJson(imageStateAsObj, ImageState.class)).filter(imageState -> imageState.id.startsWith(AZURE_SINGLE_IMAGE_FILTER)).findFirst().get();
    {
        getHost().log(Level.INFO, "=== First enumeration should create a single '%s' image", AZURE_SINGLE_IMAGE_FILTER);
        kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_SINGLE_IMAGE_FILTER);
        if (!this.isMock) {
            // Validate 1 image state is CREATED (in addition of 11 default)
            imagesAfterFirstEnum = queryDocumentsAndAssertExpectedCount(getHost(), 1 + DEFAULT_IMAGES, ImageService.FACTORY_LINK, EXACT_COUNT);
            imageAfterFirstEnum = imageFinder.apply(imagesAfterFirstEnum.documents.values());
            // Validate created image is correctly populated
            Assert.assertNotNull("Public image must have endpointType set.", imageAfterFirstEnum.endpointType);
            Assert.assertNull("Public image must NOT have endpointLink set.", imageAfterFirstEnum.endpointLink);
            Assert.assertNull("Public image must NOT have endpointLinks set.", imageAfterFirstEnum.endpointLinks);
            Assert.assertNull("Public image must NOT have tenantLinks set.", imageAfterFirstEnum.tenantLinks);
            Assert.assertEquals("Image.name is different from the id", imageAfterFirstEnum.id, imageAfterFirstEnum.name);
            Assert.assertEquals("Image.description is different from the id", imageAfterFirstEnum.id, imageAfterFirstEnum.description);
            Assert.assertEquals("Image.region is invalid", "westus", imageAfterFirstEnum.regionId);
        }
    }
    {
        getHost().log(Level.INFO, "=== Second enumeration should update the single '%s' image", AZURE_SINGLE_IMAGE_FILTER);
        if (!this.isMock) {
            // Update local image state
            updateImageState(imageAfterFirstEnum.documentSelfLink);
        }
        kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_SINGLE_IMAGE_FILTER);
        if (!this.isMock) {
            // Validate 1 image state is UPDATED (and the local update above is overridden)
            imagesAfterSecondEnum = queryDocumentsAndAssertExpectedCount(getHost(), 1 + DEFAULT_IMAGES, ImageService.FACTORY_LINK, EXACT_COUNT);
            Assert.assertEquals("Images should be the same after the two enums", imagesAfterFirstEnum.documents.keySet(), imagesAfterSecondEnum.documents.keySet());
            ImageState imageAfterSecondEnum = imageFinder.apply(imagesAfterSecondEnum.documents.values());
            Assert.assertNotEquals("Images timestamp should differ after the two enums", imageAfterFirstEnum.documentUpdateTimeMicros, imageAfterSecondEnum.documentUpdateTimeMicros);
            Assert.assertTrue("Image name is not updated correctly after second enum.", !imageAfterSecondEnum.name.contains("OVERRIDE"));
        }
    }
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Level(java.util.logging.Level) HashSet(java.util.HashSet) Utils(com.vmware.xenon.common.Utils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImagesLoadMode(com.vmware.photon.controller.model.adapters.azure.enumeration.AzureImageEnumerationAdapterService.ImagesLoadMode) Map(java.util.Map) After(org.junit.After) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) ProvisioningUtils.queryDocumentsAndAssertExpectedCount(com.vmware.photon.controller.model.tasks.ProvisioningUtils.queryDocumentsAndAssertExpectedCount) Assume(org.junit.Assume) ImageService(com.vmware.photon.controller.model.resources.ImageService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Collection(java.util.Collection) DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ImageEnumerationTaskService(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Ignore(org.junit.Ignore) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) AzureAdaptersTestUtils(com.vmware.photon.controller.model.adapters.azure.base.AzureAdaptersTestUtils) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Assert(org.junit.Assert) Collection(java.util.Collection) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 4 with EndpointType

use of com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType in project photon-model by vmware.

the class TestAWSImageEnumerationTask method createEndpointState.

private EndpointState createEndpointState() throws Throwable {
    EndpointType endpointType = EndpointType.aws;
    EndpointState endpoint;
    {
        endpoint = new EndpointState();
        endpoint.endpointType = endpointType.name();
        endpoint.id = endpointType.name() + "-id";
        endpoint.name = endpointType.name() + "-name";
        endpoint.endpointProperties = new HashMap<>();
        endpoint.endpointProperties.put(PRIVATE_KEY_KEY, this.secretKey);
        endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, this.accessKey);
    }
    EndpointAllocationTaskState allocateEndpoint = new EndpointAllocationTaskState();
    allocateEndpoint.endpointState = endpoint;
    allocateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
    allocateEndpoint.taskInfo = new TaskState();
    allocateEndpoint.taskInfo.isDirect = true;
    allocateEndpoint.tenantLinks = Arrays.asList(endpointType.name() + "-tenant");
    allocateEndpoint = TestUtils.doPost(this.host, allocateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    return allocateEndpoint.endpointState;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) HashMap(java.util.HashMap) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) TaskState(com.vmware.xenon.common.TaskState) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState)

Aggregations

EndpointType (com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType)4 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)4 HashMap (java.util.HashMap)3 QueryTop (com.vmware.photon.controller.model.query.QueryUtils.QueryTop)2 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)2 ImageEnumerationTaskState (com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState)2 TaskState (com.vmware.xenon.common.TaskState)2 Utils (com.vmware.xenon.common.Utils)2 Builder (com.vmware.xenon.services.common.QueryTask.Query.Builder)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Level (java.util.logging.Level)2 Collectors (java.util.stream.Collectors)2 Sets (com.google.common.collect.Sets)1 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)1 EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)1 RequestType (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType)1 AzureAdaptersTestUtils (com.vmware.photon.controller.model.adapters.azure.base.AzureAdaptersTestUtils)1 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)1