use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class ContainerRegistryPropertyView method pullImage.
private void pullImage() {
final AzureString title = AzureOperationBundle.title("docker|image.pull", currentRepo);
AzureTaskManager.getInstance().runInBackground(new AzureTask(null, title, false, () -> {
try {
if (Utils.isEmptyString(currentRepo) || Utils.isEmptyString(currentTag)) {
throw new Exception(REPO_TAG_NOT_AVAILABLE);
}
final Registry registry = ContainerRegistryMvpModel.getInstance().getContainerRegistry(subscriptionId, registryId);
final PrivateRegistryImageSetting setting = ContainerRegistryMvpModel.getInstance().createImageSettingWithRegistry(registry);
final String image = String.format("%s:%s", currentRepo, currentTag);
final String fullImageTagName = String.format("%s/%s", registry.loginServerUrl(), image);
DockerClient docker = DefaultDockerClient.fromEnv().build();
DockerUtil.pullImage(docker, registry.loginServerUrl(), setting.getUsername(), setting.getPassword(), fullImageTagName);
String message = String.format(IMAGE_PULL_SUCCESS, fullImageTagName);
UIUtils.showNotification(statusBar, message, MessageType.INFO);
sendTelemetry(true, subscriptionId, null);
} catch (Exception e) {
UIUtils.showNotification(statusBar, e.getMessage(), MessageType.ERROR);
sendTelemetry(false, subscriptionId, e.getMessage());
}
}));
}
use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class SettingPanel method resetFromConfig.
/**
* Function triggered in constructing the panel.
*
* @param conf configuration instance
*/
@Override
public void resetFromConfig(PushImageRunConfiguration conf) {
if (!isMavenProject()) {
containerSettingPanel.setDockerPath(DockerUtil.getDefaultDockerFilePathIfExist(getProjectBasePath()));
}
PrivateRegistryImageSetting acrInfo = conf.getPrivateRegistryImageSetting();
if (StringUtils.isEmpty(acrInfo.getPassword())) {
final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
secureStore.migratePassword(containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName(), PRIVATE_DOCKER_REGISTRY, containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName());
acrInfo.setPassword(secureStore.loadPassword(PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername()));
}
containerSettingPanel.setTxtFields(acrInfo);
// load dockerFile path from existing configuration.
if (!Utils.isEmptyString(conf.getDockerFilePath())) {
containerSettingPanel.setDockerPath(conf.getDockerFilePath());
}
containerSettingPanel.onListRegistries();
}
use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class SettingPanel method resetFromConfig.
/**
* Function triggered in constructing the panel.
*
* @param conf configuration instance
*/
@Override
public void resetFromConfig(@NotNull WebAppOnLinuxDeployConfiguration conf) {
if (!isMavenProject()) {
containerSettingPanel.setDockerPath(DockerUtil.getDefaultDockerFilePathIfExist(getProjectBasePath()));
}
// load dockerFile path from existing configuration.
if (!Utils.isEmptyString(conf.getDockerFilePath())) {
containerSettingPanel.setDockerPath(conf.getDockerFilePath());
}
final PrivateRegistryImageSetting acrInfo = conf.getPrivateRegistryImageSetting();
if (StringUtils.isNotEmpty(acrInfo.getServerUrl())) {
final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
secureStore.migratePassword(acrInfo.getServerUrl(), acrInfo.getUsername(), PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername());
acrInfo.setPassword(secureStore.loadPassword(PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername()));
}
containerSettingPanel.setTxtFields(acrInfo);
// cache for table/combo selection
defaultSubscriptionId = conf.getSubscriptionId();
defaultWebAppId = conf.getWebAppId();
defaultLocationName = conf.getLocationName();
defaultPricingTier = StringUtils.isEmpty(conf.getPricingSkuTier()) ? Constant.WEBAPP_CONTAINER_DEFAULT_PRICING_TIER : new PricingTier(conf.getPricingSkuTier(), conf.getPricingSkuSize()).toString();
defaultResourceGroup = conf.getResourceGroupName();
defaultAppServicePlanId = conf.getAppServicePlanId();
// pnlUseExisting
loadWebAppList();
// pnlCreateNew
// including related RG & Region
webAppOnLinuxDeployPresenter.onLoadSubscriptionList();
webAppOnLinuxDeployPresenter.onLoadPricingTierList();
final boolean creatingRg = conf.isCreatingNewResourceGroup();
rdoCreateResGrp.setSelected(creatingRg);
rdoUseExistResGrp.setSelected(!creatingRg);
updateResourceGroupEnabled();
if (creatingRg) {
txtNewResGrp.setText(conf.getResourceGroupName());
}
final boolean creatingAsp = conf.isCreatingNewAppServicePlan();
rdoCreateAppServicePlan.setSelected(creatingAsp);
rdoUseExistAppServicePlan.setSelected(!creatingAsp);
updateAppServicePlanEnabled();
if (creatingAsp) {
txtCreateAppServicePlan.setText(conf.getAppServicePlanName());
}
// active panel
final boolean creatingApp = conf.isCreatingNewWebAppOnLinux();
if (creatingApp) {
textAppName.setText(conf.getAppName());
}
rdoCreateNew.setSelected(creatingApp);
rdoUseExist.setSelected(!creatingApp);
updatePanelVisibility();
// default value for new resources
final DateFormat df = new SimpleDateFormat("yyMMddHHmmss");
final String date = df.format(new Date());
if (Utils.isEmptyString(textAppName.getText())) {
textAppName.setText(String.format("%s-%s", APP_NAME_PREFIX, date));
}
if (Utils.isEmptyString(txtNewResGrp.getText())) {
txtNewResGrp.setText(String.format("%s-%s", RESOURCE_GROUP_NAME_PREFIX, date));
}
if (Utils.isEmptyString(txtCreateAppServicePlan.getText())) {
txtCreateAppServicePlan.setText(String.format("%s-%s", APP_SERVICE_PLAN_NAME_PREFIX, date));
}
}
use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class SettingPanel method apply.
/**
* Function triggered by any content change events.
*
* @param webAppOnLinuxDeployConfiguration configuration instance
*/
@Override
public void apply(WebAppOnLinuxDeployConfiguration webAppOnLinuxDeployConfiguration) {
webAppOnLinuxDeployConfiguration.setDockerFilePath(containerSettingPanel.getDockerPath());
// set ACR info
webAppOnLinuxDeployConfiguration.setPrivateRegistryImageSetting(new PrivateRegistryImageSetting(containerSettingPanel.getServerUrl().replaceFirst("^https?://", "").replaceFirst("/$", ""), containerSettingPanel.getUserName(), containerSettingPanel.getPassword(), containerSettingPanel.getImageTag(), containerSettingPanel.getStartupFile()));
final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
secureStore.savePassword(PRIVATE_DOCKER_REGISTRY, containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName(), containerSettingPanel.getPassword());
webAppOnLinuxDeployConfiguration.setTargetPath(getTargetPath());
webAppOnLinuxDeployConfiguration.setTargetName(getTargetName());
// set web app info
if (rdoUseExist.isSelected()) {
// existing web app
webAppOnLinuxDeployConfiguration.setCreatingNewWebAppOnLinux(false);
IWebApp selectedWebApp = null;
final int index = webAppTable.getSelectedRow();
if (cachedWebAppList != null && index >= 0 && index < cachedWebAppList.size()) {
selectedWebApp = cachedWebAppList.get(webAppTable.getSelectedRow());
}
if (selectedWebApp != null) {
webAppOnLinuxDeployConfiguration.setWebAppId(selectedWebApp.id());
webAppOnLinuxDeployConfiguration.setAppName(selectedWebApp.name());
webAppOnLinuxDeployConfiguration.setSubscriptionId(selectedWebApp.subscriptionId());
webAppOnLinuxDeployConfiguration.setResourceGroupName(selectedWebApp.resourceGroup());
} else {
webAppOnLinuxDeployConfiguration.setWebAppId(null);
webAppOnLinuxDeployConfiguration.setAppName(null);
webAppOnLinuxDeployConfiguration.setSubscriptionId(null);
webAppOnLinuxDeployConfiguration.setResourceGroupName(null);
}
} else if (rdoCreateNew.isSelected()) {
// create new web app
webAppOnLinuxDeployConfiguration.setCreatingNewWebAppOnLinux(true);
webAppOnLinuxDeployConfiguration.setWebAppId("");
webAppOnLinuxDeployConfiguration.setAppName(textAppName.getText());
final Subscription selectedSubscription = (Subscription) comboSubscription.getSelectedItem();
if (selectedSubscription != null) {
webAppOnLinuxDeployConfiguration.setSubscriptionId(selectedSubscription.getId());
}
// resource group
if (rdoUseExistResGrp.isSelected()) {
// existing RG
webAppOnLinuxDeployConfiguration.setCreatingNewResourceGroup(false);
final ResourceGroup selectedRg = (ResourceGroup) comboResourceGroup.getSelectedItem();
if (selectedRg != null) {
webAppOnLinuxDeployConfiguration.setResourceGroupName(selectedRg.getName());
} else {
webAppOnLinuxDeployConfiguration.setResourceGroupName(null);
}
} else if (rdoCreateResGrp.isSelected()) {
// new RG
webAppOnLinuxDeployConfiguration.setCreatingNewResourceGroup(true);
webAppOnLinuxDeployConfiguration.setResourceGroupName(txtNewResGrp.getText());
}
// app service plan
if (rdoCreateAppServicePlan.isSelected()) {
webAppOnLinuxDeployConfiguration.setCreatingNewAppServicePlan(true);
webAppOnLinuxDeployConfiguration.setAppServicePlanName(txtCreateAppServicePlan.getText());
final Region selectedLocation = (Region) cbLocation.getSelectedItem();
if (selectedLocation != null) {
webAppOnLinuxDeployConfiguration.setLocationName(selectedLocation.getName());
} else {
webAppOnLinuxDeployConfiguration.setLocationName(null);
}
final PricingTier selectedPricingTier = (PricingTier) cbPricing.getSelectedItem();
if (selectedPricingTier != null) {
webAppOnLinuxDeployConfiguration.setPricingSkuTier(selectedPricingTier.getTier());
webAppOnLinuxDeployConfiguration.setPricingSkuSize(selectedPricingTier.getSize());
} else {
webAppOnLinuxDeployConfiguration.setPricingSkuTier(null);
webAppOnLinuxDeployConfiguration.setPricingSkuSize(null);
}
} else if (rdoUseExistAppServicePlan.isSelected()) {
webAppOnLinuxDeployConfiguration.setCreatingNewAppServicePlan(false);
final AppServicePlan selectedAsp = (AppServicePlan) cbExistAppServicePlan.getSelectedItem();
if (selectedAsp != null) {
webAppOnLinuxDeployConfiguration.setAppServicePlanId(selectedAsp.id());
} else {
webAppOnLinuxDeployConfiguration.setAppServicePlanId(null);
}
}
}
}
use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class PushToContainerRegistryAction method runConfiguration.
@SuppressWarnings({ "deprecation", "Duplicates" })
private void runConfiguration(@NotNull Project project) {
final RunManagerEx manager = RunManagerEx.getInstanceEx(project);
final ConfigurationFactory factory = configType.getPushImageRunConfigurationFactory();
RunnerAndConfigurationSettings settings = manager.findConfigurationByName(String.format("%s: %s", factory.getName(), project.getName()));
Observable.fromCallable(() -> {
Registry registry = ContainerRegistryMvpModel.getInstance().getContainerRegistry(currentNode.getSubscriptionId(), currentNode.getResourceId());
return ContainerRegistryMvpModel.getInstance().createImageSettingWithRegistry(registry);
}).subscribeOn(SchedulerProviderFactory.getInstance().getSchedulerProvider().io()).subscribe(ret -> {
if (settings != null) {
PushImageRunConfiguration conf = (PushImageRunConfiguration) settings.getConfiguration();
PrivateRegistryImageSetting imageSetting = conf.getPrivateRegistryImageSetting();
imageSetting.setServerUrl(ret.getServerUrl());
imageSetting.setUsername(ret.getUsername());
imageSetting.setPassword(ret.getPassword());
AzureTaskManager.getInstance().runLater(() -> openRunDialog(project, settings));
return;
}
AzureTaskManager.getInstance().runLater(() -> openRunDialog(project, ret));
}, err -> {
err.printStackTrace();
Notification notification = new Notification(NOTIFICATION_GROUP_ID, DIALOG_TITLE, err.getMessage(), NotificationType.ERROR);
Notifications.Bus.notify(notification);
});
}
Aggregations