use of com.microsoft.azure.management.resources.ResourceGroup in project azure-tools-for-java by Microsoft.
the class WebappsModule method fillWebappsNodes.
private void fillWebappsNodes() {
Map<SubscriptionDetail, List<ResourceGroup>> srgMap = AzureModel.getInstance().getSubscriptionToResourceGroupMap();
Map<ResourceGroup, List<WebApp>> rgwaMap = AzureModel.getInstance().getResourceGroupToWebAppMap();
if (srgMap != null) {
for (SubscriptionDetail sd : srgMap.keySet()) {
if (!sd.isSelected())
continue;
for (ResourceGroup rg : srgMap.get(sd)) {
for (WebApp webApp : rgwaMap.get(rg)) {
addChildNode(new WebappNode(this, webApp, rg, RUN_STATUS.equalsIgnoreCase(webApp.inner().state()) ? WEB_RUN_ICON : WEB_STOP_ICON));
}
}
}
}
}
use of com.microsoft.azure.management.resources.ResourceGroup in project azure-tools-for-java by Microsoft.
the class AzureModelController method updateResourceGroupMaps.
public static synchronized void updateResourceGroupMaps(IProgressIndicator progressIndicator) throws IOException, CanceledByUserException, AuthException {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
updateSubscriptionMaps(progressIndicator);
AzureModel azureModel = AzureModel.getInstance();
Map<ResourceGroup, List<WebApp>> rgwaMap = azureModel.createResourceGroupToWebAppMap();
Map<ResourceGroup, List<AppServicePlan>> rgspMap = azureModel.createResourceGroupToAppServicePlanMap();
for (SubscriptionDetail sd : azureModel.getSubscriptionToResourceGroupMap().keySet()) {
if (progressIndicator != null && progressIndicator.isCanceled()) {
clearAll();
throw new CanceledByUserException();
}
List<ResourceGroup> rgList = azureModel.getSubscriptionToResourceGroupMap().get(sd);
if (rgList.size() == 0) {
System.out.println("no resource groups found!");
continue;
}
Azure azure = azureManager.getAzure(sd.getSubscriptionId());
updateResGrDependency(azure, rgList, progressIndicator, rgwaMap, rgspMap);
}
azureModel.setResourceGroupToWebAppMap(rgwaMap);
azureModel.setResourceGroupToAppServicePlanMap(rgspMap);
}
use of com.microsoft.azure.management.resources.ResourceGroup in project azure-tools-for-java by Microsoft.
the class AzureSDKManager method createVirtualMachine.
public static VirtualMachine createVirtualMachine(String subscriptionId, @NotNull String name, @NotNull String resourceGroup, boolean withNewResourceGroup, @NotNull String size, @NotNull String region, final VirtualMachineImage vmImage, Object knownImage, boolean isKnownImage, final StorageAccount storageAccount, com.microsoft.tooling.msservices.model.storage.StorageAccount newStorageAccount, boolean withNewStorageAccount, final Network network, VirtualNetwork newNetwork, boolean withNewNetwork, @NotNull String subnet, @Nullable PublicIPAddress pip, boolean withNewPip, @Nullable AvailabilitySet availabilitySet, boolean withNewAvailabilitySet, @NotNull final String username, @Nullable final String password, @Nullable String publicKey) throws Exception {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
Azure azure = azureManager.getAzure(subscriptionId);
boolean isWindows;
if (isKnownImage) {
isWindows = knownImage instanceof KnownWindowsVirtualMachineImage;
} else {
isWindows = vmImage.osDiskImage().operatingSystem().equals(OperatingSystemTypes.WINDOWS);
}
// ------ Resource Group ------
VirtualMachine.DefinitionStages.WithGroup withGroup = azure.virtualMachines().define(name).withRegion(region);
Creatable<ResourceGroup> newResourceGroup = null;
VirtualMachine.DefinitionStages.WithNetwork withNetwork;
if (withNewResourceGroup) {
newResourceGroup = azure.resourceGroups().define(resourceGroup).withRegion(region);
withNetwork = withGroup.withNewResourceGroup(newResourceGroup);
} else {
withNetwork = withGroup.withExistingResourceGroup(resourceGroup);
}
// ------ Virtual Network -----
VirtualMachine.DefinitionStages.WithPublicIPAddress withPublicIpAddress;
if (withNewNetwork) {
Network.DefinitionStages.WithGroup networkWithGroup = azure.networks().define(newNetwork.name).withRegion(region);
Creatable<Network> newVirtualNetwork;
if (withNewResourceGroup) {
newVirtualNetwork = networkWithGroup.withNewResourceGroup(newResourceGroup).withAddressSpace(newNetwork.addressSpace).withSubnet(newNetwork.subnet.name, newNetwork.subnet.addressSpace);
} else {
newVirtualNetwork = networkWithGroup.withExistingResourceGroup(resourceGroup).withAddressSpace(newNetwork.addressSpace).withSubnet(newNetwork.subnet.name, newNetwork.subnet.addressSpace);
}
withPublicIpAddress = withNetwork.withNewPrimaryNetwork(newVirtualNetwork).withPrimaryPrivateIPAddressDynamic();
// withPublicIpAddress = withNetwork.withNewPrimaryNetwork("10.0.0.0/28").
// .withPrimaryPrivateIpAddressDynamic();
} else {
withPublicIpAddress = withNetwork.withExistingPrimaryNetwork(network).withSubnet(subnet).withPrimaryPrivateIPAddressDynamic();
}
// ------ Public IP Address------
VirtualMachine.DefinitionStages.WithOS withOS;
if (pip == null) {
if (withNewPip) {
withOS = withPublicIpAddress.withNewPrimaryPublicIPAddress(name + "pip");
} else {
withOS = withPublicIpAddress.withoutPrimaryPublicIPAddress();
}
} else {
withOS = withPublicIpAddress.withExistingPrimaryPublicIPAddress(pip);
}
// ------ OS and credentials -----
VirtualMachine.DefinitionStages.WithCreate withCreate;
if (isWindows) {
VirtualMachine.DefinitionStages.WithWindowsAdminUsernameManagedOrUnmanaged withWindowsAdminUsername;
if (isKnownImage) {
withWindowsAdminUsername = withOS.withPopularWindowsImage((KnownWindowsVirtualMachineImage) knownImage);
} else {
withWindowsAdminUsername = withOS.withSpecificWindowsImageVersion(vmImage.imageReference());
}
withCreate = withWindowsAdminUsername.withAdminUsername(username).withAdminPassword(password).withUnmanagedDisks();
} else {
VirtualMachine.DefinitionStages.WithLinuxRootPasswordOrPublicKeyManagedOrUnmanaged withLinuxRootPasswordOrPublicKey;
if (isKnownImage) {
withLinuxRootPasswordOrPublicKey = withOS.withPopularLinuxImage((KnownLinuxVirtualMachineImage) knownImage).withRootUsername(username);
} else {
withLinuxRootPasswordOrPublicKey = withOS.withSpecificLinuxImageVersion(vmImage.imageReference()).withRootUsername(username);
}
VirtualMachine.DefinitionStages.WithLinuxCreateManagedOrUnmanaged withLinuxCreate;
// we assume either password or public key is not empty
if (password != null && !password.isEmpty()) {
withLinuxCreate = withLinuxRootPasswordOrPublicKey.withRootPassword(password);
if (publicKey != null) {
withLinuxCreate = withLinuxCreate.withSsh(publicKey);
}
} else {
withLinuxCreate = withLinuxRootPasswordOrPublicKey.withSsh(publicKey);
}
withCreate = withLinuxCreate.withUnmanagedDisks();
}
withCreate = withCreate.withSize(size);
// ---- Storage Account --------
if (withNewStorageAccount) {
StorageAccount.DefinitionStages.WithCreate newAccount;
StorageAccount.DefinitionStages.WithGroup withGroupAccount = azure.storageAccounts().define(newStorageAccount.getName()).withRegion(newStorageAccount.getLocation());
if (newStorageAccount.isNewResourceGroup()) {
newAccount = withGroupAccount.withNewResourceGroup(newStorageAccount.getResourceGroupName());
} else {
newAccount = withGroupAccount.withExistingResourceGroup(newStorageAccount.getResourceGroupName());
}
// only general purpose accounts used to create vm
newAccount.withGeneralPurposeAccountKind().withSku(SkuName.fromString(newStorageAccount.getType()));
withCreate = withCreate.withNewStorageAccount(newAccount);
} else {
withCreate = withCreate.withExistingStorageAccount(storageAccount);
}
if (withNewAvailabilitySet) {
withCreate = withCreate.withNewAvailabilitySet(name + "as");
} else if (availabilitySet != null) {
withCreate = withCreate.withExistingAvailabilitySet(availabilitySet);
}
return withCreate.create();
}
use of com.microsoft.azure.management.resources.ResourceGroup in project azure-tools-for-java by Microsoft.
the class AppServiceCreateDialog method validated.
protected boolean validated() {
cleanError();
model.collectData();
String webappName = model.webAppName;
if (webappName.length() > 60 || !webappName.matches("^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$")) {
StringBuilder builder = new StringBuilder();
builder.append("The name can contain letters, numbers and hyphens but the first and last characters must be a letter or number. ");
builder.append("The length can be between 2 and 60 characters. ");
setError(dec_textAppName, builder.toString());
return false;
} else {
for (List<WebApp> wal : AzureModel.getInstance().getResourceGroupToWebAppMap().values()) {
for (WebApp wa : wal) {
if (wa.name().toLowerCase().equals(webappName.toLowerCase())) {
setError(dec_textAppName, "The name is already taken");
return false;
}
}
}
}
if (model.webContainer == null) {
setError(dec_comboWebContainer, "Select a valid web container.");
return false;
}
if (model.subscriptionDetail == null) {
setError(dec_comboSubscription, "Select a valid subscription.");
return false;
}
if (model.isAppServicePlanCreateNew) {
if (model.appServicePlanNameCreateNew.isEmpty()) {
setError(dec_textAppSevicePlanName, "Enter a valid App Service Plan name.");
return false;
} else {
if (!model.appServicePlanNameCreateNew.matches("^[A-Za-z0-9-]*[A-Za-z0-9-]$")) {
setError(dec_textAppSevicePlanName, "App Service Plan name can only include alphanumeric characters and hyphens.");
return false;
}
// App service plan name must be unique in each subscription
SubscriptionDetail sd = model.subscriptionDetail;
List<ResourceGroup> rgl = AzureModel.getInstance().getSubscriptionToResourceGroupMap().get(sd);
for (ResourceGroup rg : rgl) {
List<AppServicePlan> aspl = AzureModel.getInstance().getResourceGroupToAppServicePlanMap().get(rg);
for (AppServicePlan asp : aspl) {
if (asp.name().toLowerCase().equals(model.appServicePlanNameCreateNew.toLowerCase())) {
setError(dec_textAppSevicePlanName, "App service plan name must be unuque in each subscription.");
return false;
}
}
}
}
if (model.appServicePlanLocationCreateNew == null) {
setError(dec_comboAppServicePlanLocation, "Select a location.");
return false;
}
} else {
if (model.appServicePlan == null) {
setError(dec_comboAppServicePlan, "Select a valid App Service Plan.");
return false;
}
}
if (model.isResourceGroupCreateNew) {
if (model.resourceGroupNameCreateNew.isEmpty()) {
setError(dec_textNewResGrName, "Enter a valid resource group name");
return false;
} else {
if (!model.resourceGroupNameCreateNew.matches("^[A-Za-z0-9-_()\\.]*[A-Za-z0-9-_()]$")) {
setError(dec_textNewResGrName, "Resounce group name can only include alphanumeric characters, periods, underscores, hyphens, and parenthesis and can't end in a period.");
return false;
}
for (List<ResourceGroup> rgl : AzureModel.getInstance().getSubscriptionToResourceGroupMap().values()) {
for (ResourceGroup rg : rgl) {
if (rg.name().toLowerCase().equals(model.resourceGroupNameCreateNew.toLowerCase())) {
setError(dec_textNewResGrName, "The name is already taken");
return false;
}
}
}
}
} else {
if (model.resourceGroup == null) {
setError(dec_comboSelectResGr, "Select a valid resource group.");
return false;
}
}
return volidatedJdkTab();
}
use of com.microsoft.azure.management.resources.ResourceGroup in project azure-tools-for-java by Microsoft.
the class AppServiceCreateDialog method fillAppServicePlans.
protected void fillAppServicePlans() {
int i = comboSubscription.getSelectionIndex();
if (i < 0) {
// empty
System.out.println("No subscription is selected");
return;
}
List<ResourceGroup> rgl = AzureModel.getInstance().getSubscriptionToResourceGroupMap().get(binderSubscriptionDetails.get(i));
if (rgl == null) {
System.out.println("rgl is null");
return;
}
comboAppServicePlan.removeAll();
binderAppServicePlan = new ArrayList<AppServicePlan>();
for (ResourceGroup rg : rgl) {
List<AppServicePlan> aspl = AzureModel.getInstance().getResourceGroupToAppServicePlanMap().get(rg);
for (AppServicePlan asp : aspl) {
if (asp.pricingTier().toSkuDescription().tier().compareToIgnoreCase("dynamic") == 0) {
continue;
}
binderAppServicePlan.add(asp);
comboAppServicePlan.add(asp.name());
}
}
if (comboAppServicePlan.getItemCount() > 0) {
comboAppServicePlan.select(0);
}
}
Aggregations