use of com.microsoft.azure.management.resources.Deployment in project azure-sdk-for-java by Azure.
the class DeployUsingARMTemplateWithTags method runSample.
/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
final String rgName = SdkContext.randomResourceName("rgRSAT", 24);
final String deploymentName = SdkContext.randomResourceName("dpRSAT", 24);
try {
String templateJson = getTemplate();
//=============================================================
// Create resource group.
System.out.println("Creating a resource group with name: " + rgName);
azure.resourceGroups().define(rgName).withRegion(Region.US_WEST).create();
System.out.println("Created a resource group with name: " + rgName);
//=============================================================
// Create a deployment for an Azure App Service via an ARM
// template.
System.out.println("Starting a deployment for an Azure App Service: " + deploymentName);
Deployment deployment = azure.deployments().define(deploymentName).withExistingResourceGroup(rgName).withTemplate(templateJson).withParameters("{}").withMode(DeploymentMode.INCREMENTAL).create();
System.out.println("Finished a deployment for an Azure App Service: " + deploymentName);
List<DeploymentOperation> operations = deployment.deploymentOperations().list();
List<GenericResource> genericResources = new ArrayList<>();
// Getting created resources
for (DeploymentOperation operation : operations) {
if (operation.targetResource() != null) {
genericResources.add(azure.genericResources().getById(operation.targetResource().id()));
}
}
System.out.println("Resource created during deployment: " + deploymentName);
for (GenericResource genericResource : genericResources) {
System.out.println(genericResource.resourceProviderNamespace() + "/" + genericResource.resourceType() + ": " + genericResource.name());
// Tag resource
genericResource.update().withTag("label", "deploy1").apply();
}
genericResources = azure.genericResources().listByTag(rgName, "label", "deploy1");
System.out.println("Tagged resources for deployment: " + deploymentName);
for (GenericResource genericResource : genericResources) {
System.out.println(genericResource.resourceProviderNamespace() + "/" + genericResource.resourceType() + ": " + genericResource.name());
}
return true;
} catch (Exception f) {
System.out.println(f.getMessage());
f.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.management.resources.Deployment in project azure-sdk-for-java by Azure.
the class DeployVirtualMachineUsingARMTemplate method runSample.
/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
final String rgName = SdkContext.randomResourceName("rgRSAT", 24);
final String deploymentName = SdkContext.randomResourceName("dpRSAT", 24);
try {
String templateJson = DeployVirtualMachineUsingARMTemplate.getTemplate();
System.out.println(templateJson);
//=============================================================
// Create resource group.
System.out.println("Creating a resource group with name: " + rgName);
azure.resourceGroups().define(rgName).withRegion(Region.US_WEST).create();
System.out.println("Created a resource group with name: " + rgName);
//=============================================================
// Create a deployment for an Azure App Service via an ARM
// template.
System.out.println("Starting a deployment for an Azure Virtual Machine with managed disks: " + deploymentName);
azure.deployments().define(deploymentName).withExistingResourceGroup(rgName).withTemplate(templateJson).withParameters("{}").withMode(DeploymentMode.INCREMENTAL).create();
System.out.println("Started a deployment for an Azure Virtual Machine with managed disks: " + deploymentName);
Deployment deployment = azure.deployments().getByResourceGroup(rgName, deploymentName);
System.out.println("Current deployment status : " + deployment.provisioningState());
while (!(deployment.provisioningState().equalsIgnoreCase("Succeeded") || deployment.provisioningState().equalsIgnoreCase("Failed") || deployment.provisioningState().equalsIgnoreCase("Cancelled"))) {
SdkContext.sleep(10000);
deployment = azure.deployments().getByResourceGroup(rgName, deploymentName);
System.out.println("Current deployment status : " + deployment.provisioningState());
}
return true;
} catch (Exception f) {
System.out.println(f.getMessage());
f.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.management.resources.Deployment in project azure-sdk-for-java by Azure.
the class DeployUsingARMTemplateWithProgress method runSample.
/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
final String rgName = SdkContext.randomResourceName("rgRSAP", 24);
final String deploymentName = SdkContext.randomResourceName("dpRSAP", 24);
try {
String templateJson = DeployUsingARMTemplateWithProgress.getTemplate();
//=============================================================
// Create resource group.
System.out.println("Creating a resource group with name: " + rgName);
azure.resourceGroups().define(rgName).withRegion(Region.US_WEST).create();
System.out.println("Created a resource group with name: " + rgName);
//=============================================================
// Create a deployment for an Azure App Service via an ARM
// template.
System.out.println("Starting a deployment for an Azure App Service: " + deploymentName);
azure.deployments().define(deploymentName).withExistingResourceGroup(rgName).withTemplate(templateJson).withParameters("{}").withMode(DeploymentMode.INCREMENTAL).beginCreate();
System.out.println("Started a deployment for an Azure App Service: " + deploymentName);
Deployment deployment = azure.deployments().getByResourceGroup(rgName, deploymentName);
System.out.println("Current deployment status : " + deployment.provisioningState());
while (!(deployment.provisioningState().equalsIgnoreCase("Succeeded") || deployment.provisioningState().equalsIgnoreCase("Failed") || deployment.provisioningState().equalsIgnoreCase("Cancelled"))) {
SdkContext.sleep(10000);
deployment = azure.deployments().getByResourceGroup(rgName, deploymentName);
System.out.println("Current deployment status : " + deployment.provisioningState());
}
return true;
} catch (Exception f) {
System.out.println(f.getMessage());
f.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.management.resources.Deployment in project azure-sdk-for-java by Azure.
the class AzureTests method testDeployments.
/**
* Tests ARM template deployments.
* @throws IOException
* @throws CloudException
*/
@Test
public void testDeployments() throws Exception {
String testId = SdkContext.randomResourceName("", 8);
List<Deployment> deployments = azure.deployments().list();
System.out.println("Deployments: " + deployments.size());
Deployment deployment = azure.deployments().define("depl" + testId).withNewResourceGroup("rg" + testId, Region.US_WEST).withTemplateLink("https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vnet-two-subnets/azuredeploy.json", "1.0.0.0").withParametersLink("https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vnet-two-subnets/azuredeploy.parameters.json", "1.0.0.0").withMode(DeploymentMode.COMPLETE).create();
System.out.println("Created deployment: " + deployment.correlationId());
azure.resourceGroups().beginDeleteByName("rg" + testId);
}
Aggregations