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);
}
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;
}
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"));
}
}
}
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;
}
Aggregations