Search in sources :

Example 1 with InvalidFormDataException

use of com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException in project azure-tools-for-java by Microsoft.

the class CreateRedisCacheForm method okPressed.

@Override
protected void okPressed() {
    try {
        RedisCacheUtil.doValidate(currentSub, dnsNameValue, selectedLocationValue, selectedResGrpValue, selectedPriceTierValue);
        if (newResGrp) {
            for (String resGrp : sortedGroups) {
                if (selectedResGrpValue.equals(resGrp)) {
                    throw new InvalidFormDataException("The resource group " + selectedResGrpValue + " is not available");
                }
            }
        }
    } catch (InvalidFormDataException e) {
        MessageDialog.openError(getShell(), "Form Validation Error", e.getMessage());
        return;
    }
    RedisConfig config = getData();
    final Runnable runnable = () -> {
        final Operation operation = TelemetryManager.createOperation(REDIS, CREATE_REDIS);
        try {
            operation.start();
            new CreateRedisTask(config).execute();
            if (onCreate != null) {
                onCreate.run();
            }
        } catch (Exception ex) {
            EventUtil.logError(operation, ErrorType.userError, ex, null, null);
            operation.complete();
            MessageDialog.openError(getShell(), String.format(MessageHandler.getResourceString(resourceBundle, CREATING_ERROR_INDICATOR_FORMAT), dnsNameValue), ex.getMessage());
            LOG.log(String.format(MessageHandler.getResourceString(resourceBundle, CREATING_ERROR_INDICATOR_FORMAT), dnsNameValue), ex);
        }
    };
    String progressMessage = Node.getProgressMessage(AzureActionEnum.CREATE.getDoingName(), RedisCacheModule.MODULE_NAME, config.getName());
    AzureTaskManager.getInstance().runInBackground(new AzureTask<>(null, progressMessage, false, runnable));
    super.okPressed();
}
Also used : InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) IOException(java.io.IOException) RedisConfig(com.microsoft.azure.toolkit.redis.RedisConfig)

Example 2 with InvalidFormDataException

use of com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException in project azure-tools-for-java by Microsoft.

the class DockerRunDialog method validate.

private void validate() throws InvalidFormDataException {
    if (dataModel == null) {
        throw new InvalidFormDataException(MISSING_MODEL);
    }
    // docker file
    if (Utils.isEmptyString(dataModel.getDockerFilePath())) {
        throw new InvalidFormDataException(INVALID_DOCKER_FILE);
    }
    File dockerFile = Paths.get(dataModel.getDockerFilePath()).toFile();
    if (!dockerFile.exists() || !dockerFile.isFile()) {
        throw new InvalidFormDataException(INVALID_DOCKER_FILE);
    }
    // cert path
    if (dataModel.isTlsEnabled()) {
        if (Utils.isEmptyString(dataModel.getDockerCertPath())) {
            throw new InvalidFormDataException(INVALID_CERT_PATH);
        }
        File certPath = Paths.get(dataModel.getDockerCertPath()).toFile();
        if (!certPath.exists() || !certPath.isDirectory()) {
            throw new InvalidFormDataException(INVALID_CERT_PATH);
        }
    }
    String imageName = dataModel.getImageName();
    String tagName = dataModel.getTagName();
    if (Utils.isEmptyString(imageName) || Utils.isEmptyString(tagName)) {
        throw new InvalidFormDataException(MISSING_IMAGE_WITH_TAG);
    }
    // check repository first
    if (imageName.length() < 1 || imageName.length() > REPO_LENGTH) {
        throw new InvalidFormDataException(REPO_LENGTH_INVALID);
    }
    if (imageName.endsWith("/")) {
        throw new InvalidFormDataException(CANNOT_END_WITH_SLASH);
    }
    final String[] repoComponents = imageName.split("/");
    for (String component : repoComponents) {
        if (!component.matches(REPO_COMPONENTS_REGEX)) {
            throw new InvalidFormDataException(String.format(REPO_COMPONENT_INVALID, component, REPO_COMPONENTS_REGEX));
        }
    }
    // check tag
    if (tagName.length() > TAG_LENGTH) {
        throw new InvalidFormDataException(TAG_LENGTH_INVALID);
    }
    if (!tagName.matches(TAG_REGEX)) {
        throw new InvalidFormDataException(String.format(TAG_INVALID, tagName, TAG_REGEX));
    }
    // target package
    if (Utils.isEmptyString(dataModel.getTargetName())) {
        throw new InvalidFormDataException(MISSING_ARTIFACT);
    }
    if (!dataModel.getTargetName().matches(ARTIFACT_NAME_REGEX)) {
        throw new InvalidFormDataException(String.format(INVALID_ARTIFACT_FILE, dataModel.getTargetName()));
    }
}
Also used : InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) File(java.io.File)

Example 3 with InvalidFormDataException

use of com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException in project azure-tools-for-java by Microsoft.

the class PublishWebAppOnLinuxDialog method validate.

private void validate() throws InvalidFormDataException {
    if (!AuthMethodManager.getInstance().isSignedIn()) {
        throw new InvalidFormDataException(NEED_SIGN_IN);
    }
    // docker file
    if (Utils.isEmptyString(model.getDockerFilePath())) {
        throw new InvalidFormDataException(INVALID_DOCKER_FILE);
    }
    File dockerFile = Paths.get(model.getDockerFilePath()).toFile();
    if (!dockerFile.exists() || !dockerFile.isFile()) {
        throw new InvalidFormDataException(INVALID_DOCKER_FILE);
    }
    // acr
    PrivateRegistryImageSetting setting = model.getPrivateRegistryImageSetting();
    if (Utils.isEmptyString(setting.getServerUrl()) || !setting.getServerUrl().matches(DOMAIN_NAME_REGEX)) {
        throw new InvalidFormDataException(MISSING_SERVER_URL);
    }
    if (Utils.isEmptyString(setting.getUsername())) {
        throw new InvalidFormDataException(MISSING_USERNAME);
    }
    if (Utils.isEmptyString(setting.getPassword())) {
        throw new InvalidFormDataException(MISSING_PASSWORD);
    }
    String imageTag = setting.getImageTagWithServerUrl();
    if (Utils.isEmptyString(imageTag)) {
        throw new InvalidFormDataException(MISSING_IMAGE_WITH_TAG);
    }
    if (imageTag.endsWith(":")) {
        throw new InvalidFormDataException(CANNOT_END_WITH_COLON);
    }
    final String[] repoAndTag = imageTag.split(":");
    // check repository first
    if (repoAndTag[0].length() < 1 || repoAndTag[0].length() > REPO_LENGTH) {
        throw new InvalidFormDataException(REPO_LENGTH_INVALID);
    }
    if (repoAndTag[0].endsWith("/")) {
        throw new InvalidFormDataException(CANNOT_END_WITH_SLASH);
    }
    final String[] repoComponents = repoAndTag[0].split("/");
    for (String component : repoComponents) {
        if (!component.matches(REPO_COMPONENTS_REGEX)) {
            throw new InvalidFormDataException(String.format(REPO_COMPONENT_INVALID, component, REPO_COMPONENTS_REGEX));
        }
    }
    // check when contains tag
    if (repoAndTag.length == 2) {
        if (repoAndTag[1].length() > TAG_LENGTH) {
            throw new InvalidFormDataException(TAG_LENGTH_INVALID);
        }
        if (!repoAndTag[1].matches(TAG_REGEX)) {
            throw new InvalidFormDataException(String.format(TAG_INVALID, repoAndTag[1], TAG_REGEX));
        }
    }
    if (repoAndTag.length > 2) {
        throw new InvalidFormDataException(INVALID_IMAGE_WITH_TAG);
    }
    // web app
    if (model.isCreatingNewWebAppOnLinux()) {
        if (Utils.isEmptyString(model.getWebAppName())) {
            throw new InvalidFormDataException(MISSING_WEB_APP);
        }
        if (Utils.isEmptyString(model.getSubscriptionId())) {
            throw new InvalidFormDataException(MISSING_SUBSCRIPTION);
        }
        if (Utils.isEmptyString(model.getResourceGroupName())) {
            throw new InvalidFormDataException(MISSING_RESOURCE_GROUP);
        }
        if (model.isCreatingNewAppServicePlan()) {
            if (Utils.isEmptyString(model.getAppServicePlanName())) {
                throw new InvalidFormDataException(MISSING_APP_SERVICE_PLAN);
            }
        } else {
            if (Utils.isEmptyString(model.getAppServicePlanId())) {
                throw new InvalidFormDataException(MISSING_APP_SERVICE_PLAN);
            }
        }
    } else {
        if (Utils.isEmptyString(model.getWebAppId())) {
            throw new InvalidFormDataException(MISSING_WEB_APP);
        }
    }
    // target package
    if (Utils.isEmptyString(model.getTargetName())) {
        throw new InvalidFormDataException(MISSING_ARTIFACT);
    }
    if (!model.getTargetName().matches(ARTIFACT_NAME_REGEX)) {
        throw new InvalidFormDataException(String.format(INVALID_WAR_FILE, model.getTargetName()));
    }
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) File(java.io.File)

Example 4 with InvalidFormDataException

use of com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException in project azure-tools-for-java by Microsoft.

the class PushImageDialog method validate.

private void validate() throws InvalidFormDataException {
    if (model == null) {
        throw new InvalidFormDataException(MISSING_MODEL);
    }
    // docker file
    if (Utils.isEmptyString(model.getDockerFilePath())) {
        throw new InvalidFormDataException(INVALID_DOCKER_FILE);
    }
    File dockerFile = Paths.get(model.getDockerFilePath()).toFile();
    if (!dockerFile.exists() || !dockerFile.isFile()) {
        throw new InvalidFormDataException(INVALID_DOCKER_FILE);
    }
    // acr
    PrivateRegistryImageSetting setting = model.getPrivateRegistryImageSetting();
    if (Utils.isEmptyString(setting.getServerUrl()) || !setting.getServerUrl().matches(DOMAIN_NAME_REGEX)) {
        throw new InvalidFormDataException(MISSING_SERVER_URL);
    }
    if (Utils.isEmptyString(setting.getUsername())) {
        throw new InvalidFormDataException(MISSING_USERNAME);
    }
    if (Utils.isEmptyString(setting.getPassword())) {
        throw new InvalidFormDataException(MISSING_PASSWORD);
    }
    String imageTag = setting.getImageTagWithServerUrl();
    if (Utils.isEmptyString(imageTag)) {
        throw new InvalidFormDataException(MISSING_IMAGE_WITH_TAG);
    }
    if (imageTag.endsWith(":")) {
        throw new InvalidFormDataException(CANNOT_END_WITH_COLON);
    }
    final String[] repoAndTag = imageTag.split(":");
    // check repository first
    if (repoAndTag[0].length() < 1 || repoAndTag[0].length() > REPO_LENGTH) {
        throw new InvalidFormDataException(REPO_LENGTH_INVALID);
    }
    if (repoAndTag[0].endsWith("/")) {
        throw new InvalidFormDataException(CANNOT_END_WITH_SLASH);
    }
    final String[] repoComponents = repoAndTag[0].split("/");
    for (String component : repoComponents) {
        if (!component.matches(REPO_COMPONENTS_REGEX)) {
            throw new InvalidFormDataException(String.format(REPO_COMPONENT_INVALID, component, REPO_COMPONENTS_REGEX));
        }
    }
    // check when contains tag
    if (repoAndTag.length == 2) {
        if (repoAndTag[1].length() > TAG_LENGTH) {
            throw new InvalidFormDataException(TAG_LENGTH_INVALID);
        }
        if (!repoAndTag[1].matches(TAG_REGEX)) {
            throw new InvalidFormDataException(String.format(TAG_INVALID, repoAndTag[1], TAG_REGEX));
        }
    }
    if (repoAndTag.length > 2) {
        throw new InvalidFormDataException(INVALID_IMAGE_WITH_TAG);
    }
    // target package
    if (Utils.isEmptyString(model.getTargetName())) {
        throw new InvalidFormDataException(MISSING_ARTIFACT);
    }
    if (!model.getTargetName().matches(ARTIFACT_NAME_REGEX)) {
        throw new InvalidFormDataException(String.format(INVALID_ARTIFACT_FILE, model.getTargetName()));
    }
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) File(java.io.File)

Aggregations

InvalidFormDataException (com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException)4 File (java.io.File)3 PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)2 RedisConfig (com.microsoft.azure.toolkit.redis.RedisConfig)1 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)1 IOException (java.io.IOException)1