use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class AzureTestUtil method createDefaultStorageAccountDescription.
public static StorageDescription createDefaultStorageAccountDescription(VerificationHost host, String storageAccountName, ComputeState computeHost, EndpointState endpointState) throws Throwable {
AuthCredentialsServiceState auth = new AuthCredentialsServiceState();
auth.customProperties = new HashMap<>();
auth.customProperties.put(AZURE_STORAGE_ACCOUNT_KEY1, randomString(15));
auth.customProperties.put(AZURE_STORAGE_ACCOUNT_KEY2, randomString(15));
auth = TestUtils.doPost(host, auth, AuthCredentialsServiceState.class, UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK));
String authLink = UriUtils.buildUriPath(AuthCredentialsService.FACTORY_LINK, auth.documentSelfLink);
// Create a storage description
StorageDescription storageDesc = new StorageDescription();
storageDesc.id = "testStorAcct-" + randomString(4);
storageDesc.name = storageAccountName;
storageDesc.regionId = AZURE_RESOURCE_GROUP_LOCATION;
storageDesc.computeHostLink = computeHost.documentSelfLink;
storageDesc.authCredentialsLink = authLink;
storageDesc.resourcePoolLink = computeHost.resourcePoolLink;
storageDesc.tenantLinks = endpointState.tenantLinks;
storageDesc.endpointLink = endpointState.documentSelfLink;
storageDesc.endpointLinks = new HashSet<>();
storageDesc.endpointLinks.add(endpointState.documentSelfLink);
storageDesc.customProperties = new HashMap<>();
storageDesc.customProperties.put(AZURE_STORAGE_TYPE, AZURE_STORAGE_ACCOUNTS);
return TestUtils.doPost(host, storageDesc, StorageDescription.class, UriUtils.buildUri(host, StorageDescriptionService.FACTORY_LINK));
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class TestAzureProvisionTask method assertStorageDescription.
/**
* Ensure that after provisioning, there is one (but only one) StorageDescription created for
* the shared storage account. This test does not use shared SA, thus provisioning should create
* a StorageDescription.
*/
private void assertStorageDescription() {
if (this.isMock) {
// return. Nothing provisioned on Azure so nothing to check
return;
}
try {
ComputeState vm = getHost().getServiceState(null, ComputeState.class, UriUtils.buildUri(getHost(), this.vmState.documentSelfLink));
String sharedSAName = vm.customProperties.get(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME);
if (sharedSAName != null && !sharedSAName.isEmpty()) {
Map<String, StorageDescription> storageDescriptionsMap = ProvisioningUtils.<StorageDescription>getResourceStates(getHost(), StorageDescriptionService.FACTORY_LINK, StorageDescription.class);
assertTrue(!storageDescriptionsMap.isEmpty());
List<StorageDescription> storageDescriptions = storageDescriptionsMap.values().stream().filter(name -> name.equals(sharedSAName)).collect(Collectors.toList());
assertEquals("More than one storage description was created for the provisinoed storage account.", storageDescriptions.size(), 1);
}
} catch (Throwable t) {
fail("Unable to verify Storage Description documents");
t.printStackTrace();
}
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class AzureUtils method constructStorageDescription.
private static StorageDescription constructStorageDescription(StorageAccountInner sa, ServiceHost host, String serviceSelfLink, ComputeStateWithDescription parent, StorageAccountInner contextStorage, StorageAccountListKeysResultInner keys) {
AuthCredentialsServiceState storageAuth = new AuthCredentialsServiceState();
storageAuth.documentSelfLink = UUID.randomUUID().toString();
storageAuth.customProperties = new HashMap<>();
for (StorageAccountKey key : keys.keys()) {
storageAuth.customProperties.put(getStorageAccountKeyName(storageAuth.customProperties), key.value());
}
storageAuth.tenantLinks = parent.tenantLinks;
if (parent.endpointLink != null) {
storageAuth.customProperties.put(CUSTOM_PROP_ENDPOINT_LINK, parent.endpointLink);
}
Operation storageAuthOp = Operation.createPost(createInventoryUri(host, AuthCredentialsService.FACTORY_LINK)).setBody(storageAuth);
storageAuthOp.setReferer(UriUtils.buildUri(host.getPublicUri(), serviceSelfLink));
host.sendRequest(storageAuthOp);
String storageAuthLink = UriUtils.buildUriPath(AuthCredentialsService.FACTORY_LINK, storageAuth.documentSelfLink);
StorageDescription storageDescription = new StorageDescription();
storageDescription.id = contextStorage.id();
storageDescription.regionId = contextStorage.location();
storageDescription.name = contextStorage.name();
storageDescription.authCredentialsLink = storageAuthLink;
storageDescription.resourcePoolLink = parent.resourcePoolLink;
storageDescription.documentSelfLink = UUID.randomUUID().toString();
storageDescription.endpointLink = parent.endpointLink;
AdapterUtils.addToEndpointLinks(storageDescription, parent.endpointLink);
storageDescription.computeHostLink = parent.documentSelfLink;
storageDescription.customProperties = new HashMap<>();
storageDescription.customProperties.put(AZURE_STORAGE_TYPE, AZURE_STORAGE_ACCOUNTS);
storageDescription.customProperties.put(AZURE_STORAGE_ACCOUNT_URI, null);
storageDescription.tenantLinks = parent.tenantLinks;
storageDescription.type = contextStorage.sku().name().toString();
if (sa != null && sa.creationTime() != null) {
storageDescription.creationTimeMicros = TimeUnit.MILLISECONDS.toMicros(sa.creationTime().getMillis());
}
return storageDescription;
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class DiskContext method populateContextThen.
/**
* Populates the given initial context and invoke the onSuccess handler when built. At every
* step, if failure occurs the DiskContext's errorHandler is invoked to cleanup.
*/
public static void populateContextThen(Service service, DiskContext ctx, Consumer<DiskContext> onSuccess) {
// Step 1: Get disk details
if (ctx.diskState == null) {
URI diskUri = createInventoryUri(service.getHost(), DiskService.DiskStateExpanded.buildUri(ctx.diskReference));
AdapterUtils.getServiceState(service, diskUri, op -> {
ctx.diskState = op.getBody(DiskService.DiskStateExpanded.class);
EnumSet<DiskService.DiskType> notSupportedTypes = EnumSet.of(DiskService.DiskType.SSD, DiskService.DiskType.NETWORK);
if (notSupportedTypes.contains(ctx.diskState.type)) {
ctx.fail(new IllegalStateException(String.format("Not supported disk type %s.", ctx.diskState.type)));
return;
}
populateContextThen(service, ctx, onSuccess);
}, ctx.errorHandler);
return;
}
// the disk.
if (ctx.datastoreName == null && ctx.diskInstanceRequest.requestType == DiskInstanceRequest.DiskRequestType.CREATE) {
if (ctx.diskState.storageDescription != null) {
ctx.datastoreName = ctx.diskState.storageDescription.id;
populateContextThen(service, ctx, onSuccess);
} else if (ctx.diskState.resourceGroupStates != null && !ctx.diskState.resourceGroupStates.isEmpty()) {
// There will always be only one resource group state existing for a disk
ResourceGroupState resource = ctx.diskState.resourceGroupStates.iterator().next();
ClientUtils.getDatastoresForProfile(service, resource.documentSelfLink, ctx.diskState.endpointLink, ctx.diskState.tenantLinks, ctx.errorHandler, (result) -> {
if (result.documents != null && result.documents.size() > 0) {
// pick the first datastore and proceed.
StorageDescription dsStorageDesc = Utils.fromJson(result.documents.values().iterator().next(), StorageDescription.class);
ctx.datastoreName = dsStorageDesc.id;
ctx.diskState.storageDescriptionLink = dsStorageDesc.documentSelfLink;
} else {
// Since no result found default to the available datastore.
ctx.datastoreName = "";
}
populateContextThen(service, ctx, onSuccess);
});
} else if (CustomProperties.of(ctx.diskState).getString(CustomProperties.DISK_DATASTORE_NAME) != null) {
ctx.datastoreName = CustomProperties.of(ctx.diskState).getString(CustomProperties.DISK_DATASTORE_NAME);
populateContextThen(service, ctx, onSuccess);
} else {
// Mark empty so that it can fall back to any available datastore from the system.
ctx.datastoreName = "";
populateContextThen(service, ctx, onSuccess);
}
return;
}
// Step 3: Get Credentials
if (ctx.vSphereCredentials == null) {
if (IAAS_API_ENABLED) {
if (ctx.operation == null) {
ctx.fail(new IllegalArgumentException("Caller operation cannot be empty"));
return;
}
SessionUtil.retrieveExternalToken(service, ctx.operation.getAuthorizationContext()).whenComplete((authCredentialsServiceState, throwable) -> {
if (throwable != null) {
ctx.errorHandler.accept(throwable);
return;
}
ctx.vSphereCredentials = authCredentialsServiceState;
populateContextThen(service, ctx, onSuccess);
});
} else {
if (ctx.diskState.authCredentialsLink == null || ctx.diskState.authCredentialsLink.isEmpty()) {
ctx.fail(new IllegalArgumentException("Auth credentials cannot be empty"));
return;
}
URI credUri = createInventoryUri(service.getHost(), ctx.diskState.authCredentialsLink);
AdapterUtils.getServiceState(service, credUri, op -> {
ctx.vSphereCredentials = op.getBody(AuthCredentialsServiceState.class);
populateContextThen(service, ctx, onSuccess);
}, ctx.errorHandler);
}
return;
}
// Step 4: Get the endpoint compute link
if (ctx.endpointComputeLink == null) {
URI endpointUri = createInventoryUri(service.getHost(), UriUtils.buildUri(service.getHost(), ctx.diskState.endpointLink));
AdapterUtils.getServiceState(service, endpointUri, op -> {
EndpointService.EndpointState endpointState = op.getBody(EndpointService.EndpointState.class);
ctx.endpointComputeLink = endpointState.computeLink;
populateContextThen(service, ctx, onSuccess);
}, ctx.errorHandler);
return;
}
// Step 5: Get the adapter reference to from the endpoint compute link
if (ctx.adapterManagementReference == null) {
URI computeUri = createInventoryUri(service.getHost(), UriUtils.buildUri(service.getHost(), ctx.endpointComputeLink));
AdapterUtils.getServiceState(service, computeUri, op -> {
ComputeService.ComputeState computeState = op.getBody(ComputeService.ComputeState.class);
ctx.adapterManagementReference = computeState.adapterManagementReference;
populateContextThen(service, ctx, onSuccess);
}, ctx.errorHandler);
return;
}
// Step 6: Obtain reference to the datacenter moref.
if (ctx.datacenterMoRef == null) {
try {
ctx.datacenterMoRef = VimUtils.convertStringToMoRef(ctx.diskState.regionId);
} catch (IllegalArgumentException ex) {
ctx.fail(ex);
return;
}
}
onSuccess.accept(ctx);
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class VsphereDatastoreEnumerationHelper method updateStorageDescription.
private static void updateStorageDescription(VSphereIncrementalEnumerationService service, StorageDescription oldDocument, EnumerationProgress enumerationProgress, DatastoreOverlay ds, boolean fullUpdate) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
String regionId = enumerationProgress.getRegionId();
StorageDescription desc;
if (fullUpdate) {
desc = makeStorageFromResults(request, ds, regionId, enumerationProgress);
} else {
desc = makeStorageFromChanges(ds, oldDocument);
}
desc.documentSelfLink = oldDocument.documentSelfLink;
desc.resourcePoolLink = null;
if (oldDocument.tenantLinks == null) {
desc.tenantLinks = enumerationProgress.getTenantLinks();
}
service.logFine(() -> String.format("Syncing Storage %s", ds.getName()));
Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), desc.documentSelfLink)).setBody(desc).setCompletion((o, e) -> {
trackDatastore(enumerationProgress, ds).handle(o, e);
if (e == null) {
VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
VsphereEnumerationHelper.updateLocalTags(service, enumerationProgress, ds, o.getBody(ResourceState.class));
updateStorageStats(service, ds, o.getBody(ServiceDocument.class).documentSelfLink);
});
}
}).sendWith(service);
}
Aggregations