use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class WebAppUtils method createAppService.
public static WebApp createAppService(IProgressIndicator progressIndicator, CreateAppServiceModel model) throws IOException, WebAppException, InterruptedException, AzureCmdException {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return null;
}
Azure azure = azureManager.getAzure(model.subscriptionDetail.getSubscriptionId());
AppServicePlan appServicePlan = null;
if (model.isAppServicePlanCreateNew) {
AppServicePlan.DefinitionStages.WithGroup ds1 = azure.appServices().appServicePlans().define(model.appServicePlanNameCreateNew).withRegion(model.appServicePlanLocationCreateNew.name());
AppServicePlan.DefinitionStages.WithPricingTier ds2;
if (model.isResourceGroupCreateNew) {
ds2 = ds1.withNewResourceGroup(model.resourceGroupNameCreateNew);
} else {
ds2 = ds1.withExistingResourceGroup(model.resourceGroup);
}
appServicePlan = ds2.withPricingTier(model.appServicePricingTierCreateNew).withOperatingSystem(OperatingSystem.WINDOWS).create();
} else {
appServicePlan = model.appServicePlan;
}
WebApp.DefinitionStages.Blank definitionStages = azure.webApps().define(model.webAppName);
WebAppBase.DefinitionStages.WithCreate<WebApp> withCreate;
WebApp.DefinitionStages.ExistingWindowsPlanWithGroup ds1 = definitionStages.withExistingWindowsPlan(appServicePlan);
if (model.isResourceGroupCreateNew) {
withCreate = ds1.withNewResourceGroup(model.resourceGroupNameCreateNew);
} else {
withCreate = ds1.withExistingResourceGroup(model.resourceGroup);
}
if (model.jdkDownloadUrl == null) {
// no custom jdk
withCreate = withCreate.withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(model.webContainer);
}
WebApp myWebApp = withCreate.create();
if (model.jdkDownloadUrl != null) {
progressIndicator.setText("Deploying custom jdk...");
WebAppUtils.deployCustomJdk(myWebApp, model.jdkDownloadUrl, model.webContainer, progressIndicator);
}
// update cache
if (model.isResourceGroupCreateNew) {
ResourceGroup rg = azure.resourceGroups().getByName(model.resourceGroupNameCreateNew);
if (rg == null) {
throw new AzureCmdException(String.format("azure.resourceGroups().getByName(%s) returned null"), model.resourceGroupNameCreateNew);
}
AzureModelController.addNewResourceGroup(model.subscriptionDetail, rg);
AzureModelController.addNewWebAppToJustCreatedResourceGroup(rg, myWebApp);
if (model.isAppServicePlanCreateNew) {
AzureModelController.addNewAppServicePlanToJustCreatedResourceGroup(rg, appServicePlan);
} else {
// add empty list
AzureModelController.addNewAppServicePlanToJustCreatedResourceGroup(rg, null);
}
} else {
ResourceGroup rg = model.resourceGroup;
AzureModelController.addNewWebAppToExistingResourceGroup(rg, myWebApp);
if (model.isAppServicePlanCreateNew) {
//AppServicePlan asp = azure.appServices().appServicePlans().getById(myWebApp.appServicePlanId());
AzureModelController.addNewAppServicePlanToExistingResourceGroup(rg, appServicePlan);
}
}
return myWebApp;
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class ClusterManager method getClusterDetails.
private List<IClusterDetail> getClusterDetails(List<SubscriptionDetail> subscriptions, final Object project) throws AggregatedException {
ExecutorService taskExecutor = Executors.newFixedThreadPool(MAX_CONCURRENT);
final List<IClusterDetail> cachedClusterList = new ArrayList<>();
final List<Exception> aggregateExceptions = new ArrayList<>();
for (SubscriptionDetail subscription : subscriptions) {
taskExecutor.execute(new CommonRunnable<SubscriptionDetail, Exception>(subscription) {
@Override
public void runSpecificParameter(SubscriptionDetail parameter) throws IOException, HDIException, AzureCmdException {
IClusterOperation clusterOperation = new ClusterOperationImpl(project);
List<ClusterRawInfo> clusterRawInfoList = clusterOperation.listCluster(parameter);
if (clusterRawInfoList != null) {
for (ClusterRawInfo item : clusterRawInfoList) {
IClusterDetail tempClusterDetail = new ClusterDetail(parameter, item);
synchronized (ClusterManager.class) {
cachedClusterList.add(tempClusterDetail);
}
}
}
}
@Override
public void exceptionHandle(Exception e) {
synchronized (aggregateExceptions) {
aggregateExceptions.add(e);
}
}
});
}
taskExecutor.shutdown();
try {
taskExecutor.awaitTermination(TIME_OUT, TimeUnit.SECONDS);
} catch (InterruptedException exception) {
aggregateExceptions.add(exception);
}
if (aggregateExceptions.size() > 0) {
throw new AggregatedException(aggregateExceptions);
}
return cachedClusterList;
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class TableFileEditor method createVirtualNode.
private FileEditorVirtualNode<EditorPart> createVirtualNode(final String name) {
final FileEditorVirtualNode<EditorPart> node = new FileEditorVirtualNode<EditorPart>(this, name);
node.addAction(DELETE, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
deleteSelection();
}
});
node.addAction(REFRESH, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
fillGrid();
}
});
return node;
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getBlobItems.
@NotNull
public List<BlobItem> getBlobItems(@NotNull String connectionString, @NotNull BlobDirectory blobDirectory) throws AzureCmdException {
List<BlobItem> biList = new ArrayList<BlobItem>();
try {
CloudBlobClient client = getCloudBlobClient(connectionString);
String containerName = blobDirectory.getContainerName();
String delimiter = client.getDirectoryDelimiter();
CloudBlobContainer container = client.getContainerReference(containerName);
CloudBlobDirectory directory = container.getDirectoryReference(blobDirectory.getPath());
for (ListBlobItem item : directory.listBlobs()) {
String uri = item.getUri() != null ? item.getUri().toString() : "";
if (item instanceof CloudBlobDirectory) {
CloudBlobDirectory subDirectory = (CloudBlobDirectory) item;
String name = extractBlobItemName(subDirectory.getPrefix(), delimiter);
String path = Strings.nullToEmpty(subDirectory.getPrefix());
biList.add(new BlobDirectory(name, uri, containerName, path));
} else if (item instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) item;
String name = extractBlobItemName(blob.getName(), delimiter);
String path = Strings.nullToEmpty(blob.getName());
String type = "";
String cacheControlHeader = "";
String contentEncoding = "";
String contentLanguage = "";
String contentType = "";
String contentMD5Header = "";
String eTag = "";
Calendar lastModified = new GregorianCalendar();
long size = 0;
BlobProperties properties = blob.getProperties();
if (properties != null) {
if (properties.getBlobType() != null) {
type = properties.getBlobType().toString();
}
cacheControlHeader = Strings.nullToEmpty(properties.getCacheControl());
contentEncoding = Strings.nullToEmpty(properties.getContentEncoding());
contentLanguage = Strings.nullToEmpty(properties.getContentLanguage());
contentType = Strings.nullToEmpty(properties.getContentType());
contentMD5Header = Strings.nullToEmpty(properties.getContentMD5());
eTag = Strings.nullToEmpty(properties.getEtag());
if (properties.getLastModified() != null) {
lastModified.setTime(properties.getLastModified());
}
size = properties.getLength();
}
biList.add(new BlobFile(name, uri, containerName, path, type, cacheControlHeader, contentEncoding, contentLanguage, contentType, contentMD5Header, eTag, lastModified, size));
}
}
return biList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Blob Item list", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getQueueMessages.
@NotNull
public List<QueueMessage> getQueueMessages(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
List<QueueMessage> qmList = new ArrayList<QueueMessage>();
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
String queueName = queue.getName();
CloudQueue cloudQueue = client.getQueueReference(queueName);
for (CloudQueueMessage cqm : cloudQueue.peekMessages(32)) {
String id = Strings.nullToEmpty(cqm.getId());
String content = Strings.nullToEmpty(cqm.getMessageContentAsString());
Calendar insertionTime = new GregorianCalendar();
if (cqm.getInsertionTime() != null) {
insertionTime.setTime(cqm.getInsertionTime());
}
Calendar expirationTime = new GregorianCalendar();
if (cqm.getExpirationTime() != null) {
expirationTime.setTime(cqm.getExpirationTime());
}
int dequeueCount = cqm.getDequeueCount();
qmList.add(new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount));
}
return qmList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Queue Message list", t);
}
}
Aggregations