protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws MojoExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: this.mojo.getLog().info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: this.mojo.getLog().info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new MojoExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } this.mojo.getLog().info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new MojoExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } this.mojo.getLog().info(CREATE_DEPLOYMENT_SLOT_DONE); }
/** * API to create a new Deployment Slot by setting model. */ public DeploymentSlot createDeploymentSlot(@NotNull WebAppSettingModel model) throws Exception { final WebApp app = getWebAppById(model.getSubscriptionId(), model.getWebAppId()); final String name = model.getNewSlotName(); final String configurationSource = model.getNewSlotConfigurationSource(); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(name); if (configurationSource.equals(app.name())) { return definedSlot.withConfigurationFromParent().create(); } final DeploymentSlot configurationSourceSlot = app.deploymentSlots() .list() .stream() .filter(s -> configurationSource.equals(s.name())) .findAny() .orElse(null); if (configurationSourceSlot != null) { return definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); } else { return definedSlot.withBrandNewConfiguration().create(); } }