use of com.microsoft.azure.management.resources.fluentcore.model.Indexable in project azure-sdk-for-java by Azure.
the class TestResourceStreaming method createResource.
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
final String vmName = "vm" + this.testId;
System.out.println("In createResource \n\n\n");
Creatable<ResourceGroup> rgCreatable = virtualMachines.manager().resourceManager().resourceGroups().define(SdkContext.randomResourceName("rg" + vmName, 20)).withRegion(Region.US_EAST);
Creatable<StorageAccount> storageCreatable = this.storageAccounts.define(SdkContext.randomResourceName("stg", 20)).withRegion(Region.US_EAST).withNewResourceGroup(rgCreatable);
final AtomicInteger resourceCount = new AtomicInteger(0);
VirtualMachine virtualMachine = (VirtualMachine) virtualMachines.define(vmName).withRegion(Region.US_EAST).withNewResourceGroup(rgCreatable).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(SdkContext.randomResourceName("pip", 20)).withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_D1_V2).withNewStorageAccount(storageCreatable).withNewAvailabilitySet(SdkContext.randomResourceName("avset", 10)).createAsync().map(new Func1<Indexable, Resource>() {
@Override
public Resource call(Indexable resource) {
resourceCount.incrementAndGet();
Resource createdResource = (Resource) resource;
System.out.println("Created :" + createdResource.id());
return createdResource;
}
}).toBlocking().last();
Assert.assertTrue(resourceCount.get() == 7);
return virtualMachine;
}
use of com.microsoft.azure.management.resources.fluentcore.model.Indexable in project azure-sdk-for-java by Azure.
the class DAGErrorTests method testCompositeError.
@Test
public void testCompositeError() {
// Terminate on error strategy used in this task group is
// TaskGroupTerminateOnErrorStrategy::TERMINATE_ON_INPROGRESS_TASKS_COMPLETION
// Tasks marked X (B & G) will fault. B and G are not depends on each other.
// If B start at time 't0'th ms then G starts ~'t1 = (t0 + 250)'th ms.
// After B start, it asynchronously wait and emit an error at time '(t0 + 3500)' ms.
// In this setup, G gets ~3250 ms to start before B emits error. Eventually G also
// emit error.
// The final stream, emits result of all tasks that B and G directly or indirectly
// depends on and terminate with composite exception (that composes exception from
// B and G).
/**
* |--------->[M](0)
* |
* |==============>[J](1)----->[N](0)
* X |
* |------------------>[D](4)-->[B](3)--------------->[A](2)======================>[K](0)
* | ^ ^
* | | |
* [F](6)---->[E](5)--------------| |
* | | X |
* | |------->[G](4)-->[C](3)------------------
* | |
* | |============================>[L](2)---------->[P](1)=====>[Q](0)
* |
* |------------------------------------------------------------------>[H](1)----->[I](0)
*/
PancakeImpl pancakeM = new PancakeImpl("M", 250);
PancakeImpl pancakeN = new PancakeImpl("N", 250);
PancakeImpl pancakeK = new PancakeImpl("K", 250);
PancakeImpl pancakeQ = new PancakeImpl("Q", 250);
PancakeImpl pancakeI = new PancakeImpl("I", 250);
PancakeImpl pancakeJ = new PancakeImpl("J", 250);
pancakeJ.withInstantPancake(pancakeM);
pancakeJ.withInstantPancake(pancakeN);
PancakeImpl pancakeP = new PancakeImpl("P", 250);
pancakeP.withDelayedPancake(pancakeQ);
PancakeImpl pancakeH = new PancakeImpl("H", 250);
pancakeH.withInstantPancake(pancakeI);
PancakeImpl pancakeA = new PancakeImpl("A", 250);
PancakeImpl pancakeL = new PancakeImpl("L", 250);
pancakeL.withInstantPancake(pancakeP);
// Task B wait for 3500 ms then emit error
PancakeImpl pancakeB = new PancakeImpl("B", 3500, true);
pancakeB.withInstantPancake(pancakeA);
PancakeImpl pancakeC = new PancakeImpl("C", 250);
pancakeC.withInstantPancake(pancakeA);
PancakeImpl pancakeD = new PancakeImpl("D", 250);
pancakeD.withInstantPancake(pancakeB);
// Task G wait for 250 ms then emit error
PancakeImpl pancakeG = new PancakeImpl("G", 250, true);
pancakeG.withInstantPancake(pancakeC);
pancakeG.withDelayedPancake(pancakeL);
PancakeImpl pancakeE = new PancakeImpl("E", 250);
pancakeE.withInstantPancake(pancakeB);
pancakeE.withInstantPancake(pancakeG);
PancakeImpl pancakeF = new PancakeImpl("F", 250);
pancakeF.withInstantPancake(pancakeD);
pancakeF.withInstantPancake(pancakeE);
pancakeF.withInstantPancake(pancakeH);
pancakeA.withDelayedPancake(pancakeJ);
pancakeA.withDelayedPancake(pancakeK);
final Set<String> expectedToSee = new HashSet<>();
expectedToSee.add("M");
expectedToSee.add("N");
expectedToSee.add("K");
expectedToSee.add("Q");
expectedToSee.add("I");
expectedToSee.add("J");
expectedToSee.add("P");
expectedToSee.add("H");
expectedToSee.add("A");
expectedToSee.add("L");
expectedToSee.add("C");
final Set<String> seen = new HashSet<>();
final List<Throwable> exceptions = new ArrayList<>();
IPancake rootPancake = pancakeF.createAsync().map(new Func1<Indexable, IPancake>() {
@Override
public IPancake call(Indexable indexable) {
IPancake pancake = (IPancake) indexable;
String name = pancake.name();
System.out.println("map.onNext:" + name);
seen.add(name);
return pancake;
}
}).onErrorResumeNext(new Func1<Throwable, Observable<IPancake>>() {
@Override
public Observable<IPancake> call(Throwable throwable) {
System.out.println("map.onErrorResumeNext:" + throwable);
exceptions.add(throwable);
return Observable.empty();
}
}).toBlocking().last();
Assert.assertTrue(Sets.difference(expectedToSee, seen).isEmpty());
Assert.assertEquals(exceptions.size(), 1);
Assert.assertTrue(exceptions.get(0) instanceof CompositeException);
CompositeException compositeException = (CompositeException) exceptions.get(0);
Assert.assertEquals(compositeException.getExceptions().size(), 2);
for (Throwable throwable : compositeException.getExceptions()) {
String message = throwable.getMessage();
Assert.assertTrue(message.equalsIgnoreCase("B") || message.equalsIgnoreCase("G"));
}
}
use of com.microsoft.azure.management.resources.fluentcore.model.Indexable in project azure-sdk-for-java by Azure.
the class BatchAccountOperationsTests method canCRUDBatchAccount.
@Test
public void canCRUDBatchAccount() throws Exception {
// Create
Observable<Indexable> resourceStream = batchManager.batchAccounts().define(BATCH_NAME).withRegion(Region.US_CENTRAL).withNewResourceGroup(RG_NAME).createAsync();
BatchAccount batchAccount = Utils.<BatchAccount>rootResource(resourceStream).toBlocking().last();
Assert.assertEquals(RG_NAME, batchAccount.resourceGroupName());
Assert.assertNull(batchAccount.autoStorage());
// List
List<BatchAccount> accounts = batchManager.batchAccounts().listByResourceGroup(RG_NAME);
boolean found = false;
for (BatchAccount account : accounts) {
if (account.name().equals(BATCH_NAME)) {
found = true;
}
}
Assert.assertTrue(found);
// Get
batchAccount = batchManager.batchAccounts().getByResourceGroup(RG_NAME, BATCH_NAME);
Assert.assertNotNull(batchAccount);
// Get Keys
BatchAccountKeys keys = batchAccount.getKeys();
Assert.assertNotNull(keys.primary());
Assert.assertNotNull(keys.secondary());
BatchAccountKeys newKeys = batchAccount.regenerateKeys(AccountKeyType.PRIMARY);
Assert.assertNotNull(newKeys.primary());
Assert.assertNotNull(newKeys.secondary());
Assert.assertNotEquals(newKeys.primary(), keys.primary());
Assert.assertEquals(newKeys.secondary(), keys.secondary());
batchAccount = batchAccount.update().withNewStorageAccount(SA_NAME).apply();
Assert.assertNotNull(batchAccount.autoStorage().storageAccountId());
Assert.assertNotNull(batchAccount.autoStorage().lastKeySync());
DateTime lastSync = batchAccount.autoStorage().lastKeySync();
batchAccount.synchronizeAutoStorageKeys();
batchAccount.refresh();
Assert.assertNotEquals(lastSync, batchAccount.autoStorage().lastKeySync());
// Test applications.
String applicationId = "myApplication";
String applicationDisplayName = "displayName";
String applicationPackageName = "applicationPackage";
boolean updatesAllowed = true;
batchAccount.update().defineNewApplication(applicationId).defineNewApplicationPackage(applicationPackageName).withDisplayName(applicationDisplayName).withAllowUpdates(updatesAllowed).attach().apply();
Assert.assertTrue(batchAccount.applications().containsKey(applicationId));
// Refresh to fetch batch account and application again.
batchAccount.refresh();
Assert.assertTrue(batchAccount.applications().containsKey(applicationId));
Application application = batchAccount.applications().get(applicationId);
Assert.assertEquals(application.displayName(), applicationDisplayName);
Assert.assertEquals(application.updatesAllowed(), updatesAllowed);
Assert.assertEquals(1, application.applicationPackages().size());
ApplicationPackage applicationPackage = application.applicationPackages().get(applicationPackageName);
Assert.assertEquals(applicationPackage.name(), applicationPackageName);
// Delete application package directly.
applicationPackage.delete();
batchAccount.update().withoutApplication(applicationId).apply();
SdkContext.sleep(30 * 1000);
batchAccount.refresh();
Assert.assertFalse(batchAccount.applications().containsKey(applicationId));
String applicationPackage1Name = "applicationPackage1";
String applicationPackage2Name = "applicationPackage2";
batchAccount.update().defineNewApplication(applicationId).defineNewApplicationPackage(applicationPackage1Name).defineNewApplicationPackage(applicationPackage2Name).withDisplayName(applicationDisplayName).withAllowUpdates(updatesAllowed).attach().apply();
Assert.assertTrue(batchAccount.applications().containsKey(applicationId));
application.refresh();
Assert.assertEquals(2, application.applicationPackages().size());
String newApplicationDisplayName = "newApplicationDisplayName";
batchAccount.update().updateApplication(applicationId).withoutApplicationPackage(applicationPackage2Name).withDisplayName(newApplicationDisplayName).parent().apply();
application = batchAccount.applications().get(applicationId);
Assert.assertEquals(application.displayName(), newApplicationDisplayName);
batchAccount.refresh();
application = batchAccount.applications().get(applicationId);
Assert.assertEquals(application.displayName(), newApplicationDisplayName);
Assert.assertEquals(1, application.applicationPackages().size());
applicationPackage = application.applicationPackages().get(applicationPackage1Name);
Assert.assertNotNull(applicationPackage);
String id = applicationPackage.id();
Assert.assertNotNull(applicationPackage.id());
Assert.assertEquals(applicationPackage.name(), applicationPackage1Name);
Assert.assertNull(applicationPackage.format());
batchAccount.update().updateApplication(applicationId).withoutApplicationPackage(applicationPackage1Name).parent().apply();
batchManager.batchAccounts().deleteByResourceGroup(batchAccount.resourceGroupName(), batchAccount.name());
batchAccount = batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertNull(batchAccount);
}
use of com.microsoft.azure.management.resources.fluentcore.model.Indexable in project azure-sdk-for-java by Azure.
the class HostNameBindingImpl method createAsync.
@Override
public Observable<Indexable> createAsync() {
final HostNameBinding self = this;
Func1<HostNameBindingInner, HostNameBinding> mapper = new Func1<HostNameBindingInner, HostNameBinding>() {
@Override
public HostNameBinding call(HostNameBindingInner hostNameBindingInner) {
setInner(hostNameBindingInner);
return self;
}
};
Observable<HostNameBinding> hostNameBindingObservable;
if (parent instanceof DeploymentSlot) {
hostNameBindingObservable = this.parent().manager().inner().webApps().createOrUpdateHostNameBindingSlotAsync(parent().resourceGroupName(), ((DeploymentSlot) parent).parent().name(), name, parent().name(), inner()).map(mapper);
} else {
hostNameBindingObservable = this.parent().manager().inner().webApps().createOrUpdateHostNameBindingAsync(parent().resourceGroupName(), parent().name(), name, inner()).map(mapper);
}
return hostNameBindingObservable.map(new Func1<HostNameBinding, Indexable>() {
@Override
public Indexable call(HostNameBinding hostNameBinding) {
return hostNameBinding;
}
});
}
use of com.microsoft.azure.management.resources.fluentcore.model.Indexable in project azure-sdk-for-java by Azure.
the class VirtualMachineOperationsTests method canStreamParallelCreatedVirtualMachinesAndRelatedResources.
@Test
public void canStreamParallelCreatedVirtualMachinesAndRelatedResources() throws Exception {
String vmNamePrefix = "vmz";
String publicIpNamePrefix = generateRandomResourceName("pip-", 15);
String networkNamePrefix = generateRandomResourceName("vnet-", 15);
int count = 5;
final Set<String> virtualMachineNames = new HashSet<>();
for (int i = 0; i < count; i++) {
virtualMachineNames.add(String.format("%s-%d", vmNamePrefix, i));
}
final Set<String> networkNames = new HashSet<>();
for (int i = 0; i < count; i++) {
networkNames.add(String.format("%s-%d", networkNamePrefix, i));
}
final Set<String> publicIPAddressNames = new HashSet<>();
for (int i = 0; i < count; i++) {
publicIPAddressNames.add(String.format("%s-%d", publicIpNamePrefix, i));
}
final CreatablesInfo creatablesInfo = prepareCreatableVirtualMachines(REGION, vmNamePrefix, networkNamePrefix, publicIpNamePrefix, count);
final AtomicInteger resourceCount = new AtomicInteger(0);
List<Creatable<VirtualMachine>> virtualMachineCreatables = creatablesInfo.virtualMachineCreatables;
computeManager.virtualMachines().createAsync(virtualMachineCreatables).map(new Func1<Indexable, Indexable>() {
@Override
public Indexable call(Indexable createdResource) {
if (createdResource instanceof Resource) {
Resource resource = (Resource) createdResource;
System.out.println("Created: " + resource.id());
if (resource instanceof VirtualMachine) {
VirtualMachine virtualMachine = (VirtualMachine) resource;
Assert.assertTrue(virtualMachineNames.contains(virtualMachine.name()));
Assert.assertNotNull(virtualMachine.id());
} else if (resource instanceof Network) {
Network network = (Network) resource;
Assert.assertTrue(networkNames.contains(network.name()));
Assert.assertNotNull(network.id());
} else if (resource instanceof PublicIPAddress) {
PublicIPAddress publicIPAddress = (PublicIPAddress) resource;
Assert.assertTrue(publicIPAddressNames.contains(publicIPAddress.name()));
Assert.assertNotNull(publicIPAddress.id());
}
}
resourceCount.incrementAndGet();
return createdResource;
}
}).toBlocking().last();
// 1 resource group, 1 storage, 5 network, 5 publicIp, 5 nic, 5 virtual machines
// Additional one for CreatableUpdatableResourceRoot.
// TODO - ans - We should not emit CreatableUpdatableResourceRoot.
Assert.assertEquals(resourceCount.get(), 23);
}
Aggregations