use of com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount in project azure-sdk-for-java by Azure.
the class DataLakeAnalyticsAccountOperationsTests method canCreateGetUpdateDeleteAdlaAccount.
@Test
public void canCreateGetUpdateDeleteAdlaAccount() throws Exception {
String adlaAcct = generateRandomResourceName("adla", 15);
String storageAcct = generateRandomResourceName("wasb", 15);
String adlsName2 = generateRandomResourceName("adls2", 15);
// Create
storageManagementClient.storageAccounts().define(storageAcct).withRegion(environmentLocation).withExistingResourceGroup(rgName).withSku(SkuName.STANDARD_LRS).withGeneralPurposeAccountKind().create();
String storageAccessKey = storageManagementClient.storageAccounts().getByResourceGroup(rgName, storageAcct).getKeys().get(0).value();
// create second ADLS account
DataLakeStoreAccount adlsCreateParams = new DataLakeStoreAccount();
adlsCreateParams.withLocation(environmentLocation.name());
dataLakeStoreAccountManagementClient.accounts().create(rgName, adlsName2, adlsCreateParams);
List<DataLakeStoreAccountInfo> adlsAccts = new ArrayList<DataLakeStoreAccountInfo>();
DataLakeStoreAccountInfo adlsInfo = new DataLakeStoreAccountInfo();
adlsInfo.withName(adlsName);
adlsAccts.add(adlsInfo);
DataLakeAnalyticsAccount createParams = new DataLakeAnalyticsAccount();
createParams.withLocation(environmentLocation.name());
createParams.withDataLakeStoreAccounts(adlsAccts);
createParams.withDefaultDataLakeStoreAccount(adlsName);
HashMap<String, String> tags = new HashMap<String, String>();
tags.put("testkey", "testvalue");
createParams.withTags(tags);
DataLakeAnalyticsAccount createResponse = dataLakeAnalyticsAccountManagementClient.accounts().create(rgName, adlaAcct, createParams);
Assert.assertEquals(environmentLocation.name(), createResponse.location());
Assert.assertEquals("Microsoft.DataLakeAnalytics/accounts", createResponse.type());
Assert.assertNotNull(createResponse.id());
Assert.assertTrue(createResponse.id().contains(adlaAcct));
Assert.assertEquals(1, createResponse.getTags().size());
Assert.assertEquals(1, createResponse.dataLakeStoreAccounts().size());
Assert.assertEquals(adlsName, createResponse.dataLakeStoreAccounts().get(0).name());
// update the tags
DataLakeAnalyticsAccountUpdateParameters updateParams = new DataLakeAnalyticsAccountUpdateParameters();
createParams.getTags().put("testkey2", "testvalue2");
updateParams.withTags(createParams.getTags());
DataLakeAnalyticsAccount updateResponse = dataLakeAnalyticsAccountManagementClient.accounts().update(rgName, adlaAcct, updateParams);
Assert.assertEquals(environmentLocation.name(), updateResponse.location());
Assert.assertEquals("Microsoft.DataLakeAnalytics/accounts", updateResponse.type());
Assert.assertNotNull(updateResponse.id());
Assert.assertTrue(updateResponse.id().contains(adlaAcct));
Assert.assertEquals(2, updateResponse.getTags().size());
Assert.assertEquals(1, updateResponse.dataLakeStoreAccounts().size());
Assert.assertEquals(adlsName, updateResponse.dataLakeStoreAccounts().get(0).name());
// get the account
DataLakeAnalyticsAccount getResponse = dataLakeAnalyticsAccountManagementClient.accounts().get(rgName, adlaAcct);
Assert.assertEquals(environmentLocation.name(), getResponse.location());
Assert.assertEquals("Microsoft.DataLakeAnalytics/accounts", getResponse.type());
Assert.assertNotNull(getResponse.id());
Assert.assertTrue(getResponse.id().contains(adlaAcct));
Assert.assertEquals(2, getResponse.getTags().size());
Assert.assertEquals(1, getResponse.dataLakeStoreAccounts().size());
Assert.assertEquals(adlsName, getResponse.dataLakeStoreAccounts().get(0).name());
// list all accounts and make sure there is one.
List<DataLakeAnalyticsAccount> listResult = dataLakeAnalyticsAccountManagementClient.accounts().list();
DataLakeAnalyticsAccount discoveredAcct = null;
for (DataLakeAnalyticsAccount acct : listResult) {
if (acct.name().equals(adlaAcct)) {
discoveredAcct = acct;
break;
}
}
Assert.assertNotNull(discoveredAcct);
Assert.assertEquals(environmentLocation.name(), discoveredAcct.location());
Assert.assertEquals("Microsoft.DataLakeAnalytics/accounts", discoveredAcct.type());
Assert.assertNotNull(discoveredAcct.id());
Assert.assertTrue(discoveredAcct.id().contains(adlaAcct));
Assert.assertEquals(2, discoveredAcct.getTags().size());
// the properties should be empty when we do list calls
Assert.assertNull(discoveredAcct.dataLakeStoreAccounts());
// list within a resource group
listResult = dataLakeAnalyticsAccountManagementClient.accounts().listByResourceGroup(rgName);
discoveredAcct = null;
for (DataLakeAnalyticsAccount acct : listResult) {
if (acct.name().equals(adlaAcct)) {
discoveredAcct = acct;
break;
}
}
Assert.assertNotNull(discoveredAcct);
Assert.assertEquals(environmentLocation.name(), discoveredAcct.location());
Assert.assertEquals("Microsoft.DataLakeAnalytics/accounts", discoveredAcct.type());
Assert.assertNotNull(discoveredAcct.id());
Assert.assertTrue(discoveredAcct.id().contains(adlaAcct));
Assert.assertEquals(2, discoveredAcct.getTags().size());
// the properties should be empty when we do list calls
Assert.assertNull(discoveredAcct.dataLakeStoreAccounts());
// Add, list, get and remove a data lake store account
AddDataLakeStoreParameters addAdlsParams = new AddDataLakeStoreParameters();
// This needs to be set and empty for now due to the front end expecting a valid json body
dataLakeAnalyticsAccountManagementClient.dataLakeStoreAccounts().add(rgName, adlaAcct, adlsName2, addAdlsParams);
// list ADLS accounts
List<DataLakeStoreAccountInfo> adlsListResult = dataLakeAnalyticsAccountManagementClient.dataLakeStoreAccounts().listByAccount(rgName, adlaAcct);
Assert.assertEquals(2, adlsListResult.size());
// get the one we just added
DataLakeStoreAccountInfo adlsGetResult = dataLakeAnalyticsAccountManagementClient.dataLakeStoreAccounts().get(rgName, adlaAcct, adlsName2);
Assert.assertEquals(adlsName2, adlsGetResult.name());
// Remove the data source
dataLakeAnalyticsAccountManagementClient.dataLakeStoreAccounts().delete(rgName, adlaAcct, adlsName2);
// list again, confirming there is only one ADLS account
adlsListResult = dataLakeAnalyticsAccountManagementClient.dataLakeStoreAccounts().listByAccount(rgName, adlaAcct);
Assert.assertEquals(1, adlsListResult.size());
// Add, list get and remove an azure blob account
AddStorageAccountParameters addStoreParams = new AddStorageAccountParameters();
addStoreParams.withAccessKey(storageAccessKey);
dataLakeAnalyticsAccountManagementClient.storageAccounts().add(rgName, adlaAcct, storageAcct, addStoreParams);
// list ADLS accounts
List<StorageAccountInfo> storeListResult = dataLakeAnalyticsAccountManagementClient.storageAccounts().listByAccount(rgName, adlaAcct);
Assert.assertEquals(1, storeListResult.size());
// get the one we just added
StorageAccountInfo storageGetResult = dataLakeAnalyticsAccountManagementClient.storageAccounts().get(rgName, adlaAcct, storageAcct);
Assert.assertEquals(storageAcct, storageGetResult.name());
// Remove the data source
dataLakeAnalyticsAccountManagementClient.storageAccounts().delete(rgName, adlaAcct, storageAcct);
// list again, confirming there is only one ADLS account
storeListResult = dataLakeAnalyticsAccountManagementClient.storageAccounts().listByAccount(rgName, adlaAcct);
Assert.assertEquals(0, storeListResult.size());
// Delete the ADLA account
dataLakeAnalyticsAccountManagementClient.accounts().delete(rgName, adlaAcct);
// Do it again, it should not throw
dataLakeAnalyticsAccountManagementClient.accounts().delete(rgName, adlaAcct);
}
use of com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount in project azure-sdk-for-java by Azure.
the class DataLakeAnalyticsManagementTestBase method initializeClients.
@Override
protected void initializeClients(RestClient restClient, String defaultSubscription, String domain) {
rgName = generateRandomResourceName("adlarg", 15);
adlsName = generateRandomResourceName("adls", 15);
jobAndCatalogAdlaName = generateRandomResourceName("secondadla", 15);
environmentLocation = Region.US_EAST2;
dataLakeAnalyticsAccountManagementClient = new DataLakeAnalyticsAccountManagementClientImpl(restClient).withSubscriptionId(defaultSubscription);
// TODO: in the future this needs to be dynamic depending on the Azure environment
// the tests are running in.
String adlaSuffix = "azuredatalakeanalytics.net";
addTextReplacementRule("https://(.*)." + adlaSuffix, this.mockUri());
// Generate creds and a set of rest clients for catalog and job
ApplicationTokenCredentials credentials = new AzureTestCredentials();
if (IS_RECORD) {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
try {
credentials = ApplicationTokenCredentials.fromFile(credFile);
} catch (IOException e) {
Assert.fail("Failed to read credentials from file: " + credFile + " with error: " + e.getMessage());
}
}
if (IS_RECORD) {
RestClient restClientWithTimeout = buildRestClient(new RestClient.Builder().withConnectionTimeout(5, TimeUnit.MINUTES).withBaseUrl("https://{accountName}.{adlaJobDnsSuffix}").withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), IS_MOCKED);
dataLakeAnalyticsJobManagementClient = new DataLakeAnalyticsJobManagementClientImpl(restClientWithTimeout).withAdlaJobDnsSuffix(adlaSuffix);
RestClient catalogRestClient = buildRestClient(new RestClient.Builder().withBaseUrl("https://{accountName}.{adlaCatalogDnsSuffix}").withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), IS_MOCKED);
dataLakeAnalyticsCatalogManagementClient = new DataLakeAnalyticsCatalogManagementClientImpl(catalogRestClient).withAdlaCatalogDnsSuffix(adlaSuffix);
} else {
// for mocked clients, we can just use the basic rest client, since the DNS is replaced.
dataLakeAnalyticsCatalogManagementClient = new DataLakeAnalyticsCatalogManagementClientImpl(restClient);
dataLakeAnalyticsJobManagementClient = new DataLakeAnalyticsJobManagementClientImpl(restClient);
}
resourceManagementClient = ResourceManager.authenticate(restClient).withSubscription(defaultSubscription);
dataLakeStoreAccountManagementClient = new DataLakeStoreAccountManagementClientImpl(restClient).withSubscriptionId(defaultSubscription);
storageManagementClient = StorageManager.authenticate(restClient, defaultSubscription);
// create the resource group, ADLS account and ADLA account for job and catalog use.
resourceManagementClient.resourceGroups().define(rgName).withRegion(environmentLocation).create();
DataLakeStoreAccount createParams = new DataLakeStoreAccount();
createParams.withLocation(environmentLocation.name());
dataLakeStoreAccountManagementClient.accounts().create(rgName, adlsName, createParams);
List<DataLakeStoreAccountInfo> adlsAccts = new ArrayList<DataLakeStoreAccountInfo>();
DataLakeStoreAccountInfo adlsInfo = new DataLakeStoreAccountInfo();
adlsInfo.withName(adlsName);
adlsAccts.add(adlsInfo);
DataLakeAnalyticsAccount adlaCreateParams = new DataLakeAnalyticsAccount();
adlaCreateParams.withLocation(environmentLocation.name());
adlaCreateParams.withDataLakeStoreAccounts(adlsAccts);
adlaCreateParams.withDefaultDataLakeStoreAccount(adlsName);
dataLakeAnalyticsAccountManagementClient.accounts().create(rgName, jobAndCatalogAdlaName, adlaCreateParams);
}
use of com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount in project azure-sdk-for-java by Azure.
the class DataLakeStoreAccountOperationsTests method canCreateGetUpdateDeleteAdlsAccount.
@Test
public void canCreateGetUpdateDeleteAdlsAccount() throws Exception {
String adlsAcct = generateRandomResourceName("adlsacct", 15);
// Create
DataLakeStoreAccount createParams = new DataLakeStoreAccount();
createParams.withLocation(environmentLocation.name());
createParams.withTags(new HashMap<String, String>());
createParams.getTags().put("testkey", "testvalue");
DataLakeStoreAccount createResponse = dataLakeStoreAccountManagementClient.accounts().create(resourceGroupName, adlsAcct, createParams);
Assert.assertEquals(environmentLocation.name(), createResponse.location());
Assert.assertEquals("Microsoft.DataLakeStore/accounts", createResponse.type());
Assert.assertNotNull(createResponse.id());
Assert.assertTrue(createResponse.id().contains(adlsAcct));
Assert.assertEquals(1, createResponse.getTags().size());
// update the tags
createParams.getTags().put("testkey2", "testvalue2");
DataLakeStoreAccountUpdateParameters updateParams = new DataLakeStoreAccountUpdateParameters();
updateParams.withTags((createParams.getTags()));
DataLakeStoreAccount updateResponse = dataLakeStoreAccountManagementClient.accounts().update(resourceGroupName, adlsAcct, updateParams);
Assert.assertEquals(environmentLocation.name(), updateResponse.location());
Assert.assertEquals("Microsoft.DataLakeStore/accounts", updateResponse.type());
Assert.assertNotNull(updateResponse.id());
Assert.assertTrue(updateResponse.id().contains(adlsAcct));
Assert.assertEquals(2, updateResponse.getTags().size());
// get the account
DataLakeStoreAccount getResponse = dataLakeStoreAccountManagementClient.accounts().get(resourceGroupName, adlsAcct);
Assert.assertEquals(environmentLocation.name(), getResponse.location());
Assert.assertEquals("Microsoft.DataLakeStore/accounts", getResponse.type());
Assert.assertNotNull(getResponse.id());
Assert.assertTrue(getResponse.id().contains(adlsAcct));
Assert.assertEquals(2, getResponse.getTags().size());
// list all accounts and make sure there is one.
List<DataLakeStoreAccount> listResult = dataLakeStoreAccountManagementClient.accounts().list();
DataLakeStoreAccount discoveredAcct = null;
for (DataLakeStoreAccount acct : listResult) {
if (acct.name().equals(adlsAcct)) {
discoveredAcct = acct;
break;
}
}
Assert.assertNotNull(discoveredAcct);
Assert.assertEquals(environmentLocation.name(), discoveredAcct.location());
Assert.assertEquals("Microsoft.DataLakeStore/accounts", discoveredAcct.type());
Assert.assertNotNull(discoveredAcct.id());
Assert.assertTrue(discoveredAcct.id().contains(adlsAcct));
Assert.assertEquals(2, discoveredAcct.getTags().size());
// the properties should be empty when we do list calls
Assert.assertNull(discoveredAcct.defaultGroup());
// list within a resource group
listResult = dataLakeStoreAccountManagementClient.accounts().listByResourceGroup(resourceGroupName);
discoveredAcct = null;
for (DataLakeStoreAccount acct : listResult) {
if (acct.name().equals(adlsAcct)) {
discoveredAcct = acct;
break;
}
}
Assert.assertNotNull(discoveredAcct);
Assert.assertEquals(environmentLocation.name(), discoveredAcct.location());
Assert.assertEquals("Microsoft.DataLakeStore/accounts", discoveredAcct.type());
Assert.assertNotNull(discoveredAcct.id());
Assert.assertTrue(discoveredAcct.id().contains(adlsAcct));
Assert.assertEquals(2, discoveredAcct.getTags().size());
// the properties should be empty when we do list calls
Assert.assertNull(discoveredAcct.defaultGroup());
// Delete the ADLS account
dataLakeStoreAccountManagementClient.accounts().delete(resourceGroupName, adlsAcct);
// Do it again, it should not throw
dataLakeStoreAccountManagementClient.accounts().delete(resourceGroupName, adlsAcct);
}
Aggregations