Search in sources :

Example 1 with DeploymentResource

use of com.microsoft.azure.maven.model.DeploymentResource in project azure-maven-plugins by microsoft.

the class PackageMojo method getResources.

@Override
public List<DeploymentResource> getResources() {
    final DeploymentResource resource = new DeploymentResource();
    resource.setDirectory(getBuildDirectoryAbsolutePath());
    resource.setTargetPath("/");
    resource.setFiltering(false);
    resource.setIncludes(Collections.singletonList("*.jar"));
    return Collections.singletonList(resource);
}
Also used : DeploymentResource(com.microsoft.azure.maven.model.DeploymentResource)

Example 2 with DeploymentResource

use of com.microsoft.azure.maven.model.DeploymentResource in project azure-maven-plugins by microsoft.

the class ConfigParser method convertOneDeployResourceToArtifacts.

private static List<WebAppArtifact> convertOneDeployResourceToArtifacts(Resource resource) {
    final List<File> artifacts = MavenArtifactUtils.getArtifacts(resource);
    final String typeString = ((DeploymentResource) resource).getType();
    final DeployType type = DeployType.fromString(typeString);
    Objects.requireNonNull(type, () -> String.format("Unsupported resource type '%s', please change to one from this list: %s", typeString, DeployType.values().stream().map(Object::toString).map(StringUtils::lowerCase).collect(Collectors.joining(", "))));
    if (type.requireSingleFile() && artifacts.size() > 1) {
        throw new AzureToolkitRuntimeException(String.format("Multiple files are found for resource type('%s'), only one file is allowed.", type));
    }
    if (artifacts.isEmpty()) {
        Log.warn(String.format("Cannot find any files defined by resource(%s)", StringUtils.firstNonBlank(resource.toString())));
    }
    if (type.ignorePath() && StringUtils.isNotBlank(resource.getTargetPath())) {
        throw new AzureToolkitRuntimeException(String.format("'<targetPath>' is not allowed for deployable type('%s').", type));
    }
    if (StringUtils.isNotBlank(type.getFileExt())) {
        final String expectFileExtension = type.getFileExt();
        for (final File file : artifacts) {
            if (!StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(file.getName()), expectFileExtension)) {
                throw new AzureToolkitRuntimeException(String.format("Wrong file '%s' Deployable type('%s'), expected file type '%s'", file, type, expectFileExtension));
            }
        }
    }
    return artifacts.stream().map(file -> WebAppArtifact.builder().file(file).deployType(type).path(getRemotePath(type, resource, file)).build()).collect(Collectors.toList());
}
Also used : DeployType(com.microsoft.azure.toolkit.lib.appservice.model.DeployType) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) AbstractWebAppMojo(com.microsoft.azure.maven.webapp.AbstractWebAppMojo) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) ExpandableParameter(com.microsoft.azure.toolkit.lib.common.model.ExpandableParameter) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Region(com.microsoft.azure.toolkit.lib.common.model.Region) Matcher(java.util.regex.Matcher) WebContainer(com.microsoft.azure.toolkit.lib.appservice.model.WebContainer) Nonnull(javax.annotation.Nonnull) MavenArtifactUtils(com.microsoft.azure.maven.utils.MavenArtifactUtils) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) Runtime(com.microsoft.azure.toolkit.lib.appservice.model.Runtime) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion) DeploymentResource(com.microsoft.azure.maven.model.DeploymentResource) WebAppArtifact(com.microsoft.azure.toolkit.lib.appservice.model.WebAppArtifact) Collectors(java.util.stream.Collectors) File(java.io.File) RuntimeConfig(com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig) Deployment(com.microsoft.azure.maven.webapp.configuration.Deployment) Objects(java.util.Objects) MavenRuntimeConfig(com.microsoft.azure.maven.webapp.configuration.MavenRuntimeConfig) List(java.util.List) Resource(org.apache.maven.model.Resource) Paths(java.nio.file.Paths) DeploymentSlotConfig(com.microsoft.azure.maven.webapp.configuration.DeploymentSlotConfig) Optional(java.util.Optional) Log(com.microsoft.azure.toolkit.lib.common.logging.Log) DeployType(com.microsoft.azure.toolkit.lib.appservice.model.DeployType) OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) Collections(java.util.Collections) WebAppConfiguration(com.microsoft.azure.maven.webapp.WebAppConfiguration) FilenameUtils(org.apache.commons.io.FilenameUtils) MavenDockerCredentialProvider(com.microsoft.azure.maven.MavenDockerCredentialProvider) DeploymentResource(com.microsoft.azure.maven.model.DeploymentResource) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) File(java.io.File)

Example 3 with DeploymentResource

use of com.microsoft.azure.maven.model.DeploymentResource in project azure-maven-plugins by microsoft.

the class ConfigurationSerializer method createResourcesNode.

protected DOMElement createResourcesNode(List<DeploymentResource> resources) {
    final DOMElement resourceRootNode = new DOMElement("resources");
    for (final DeploymentResource resource : resources) {
        final DOMElement resourceNode = new DOMElement("resource");
        XMLUtils.addNotEmptyElement(resourceNode, "type", resource.getType());
        XMLUtils.addNotEmptyElement(resourceNode, "filtering", resource.getFiltering());
        XMLUtils.addNotEmptyElement(resourceNode, "mergeId", resource.getMergeId());
        XMLUtils.addNotEmptyElement(resourceNode, "targetPath", resource.getTargetPath());
        XMLUtils.addNotEmptyElement(resourceNode, "directory", resource.getDirectory());
        XMLUtils.addNotEmptyListElement(resourceNode, "includes", "include", resource.getIncludes());
        XMLUtils.addNotEmptyListElement(resourceNode, "excludes", "exclude", resource.getExcludes());
        resourceRootNode.add(resourceNode);
    }
    return resourceRootNode;
}
Also used : DeploymentResource(com.microsoft.azure.maven.model.DeploymentResource) DOMElement(org.dom4j.dom.DOMElement)

Example 4 with DeploymentResource

use of com.microsoft.azure.maven.model.DeploymentResource in project azure-maven-plugins by microsoft.

the class DeployExternalResourcesTask method deployExternalResources.

private void deployExternalResources(final IAppService<?> target, final List<DeploymentResource> resources) {
    if (resources.isEmpty()) {
        return;
    }
    AzureMessager.getMessager().info(AzureString.format("Uploading resources to %s", target.name()));
    final PublishingProfile publishingProfile = target.getPublishingProfile();
    final String serverUrl = publishingProfile.getFtpUrl().split("/", 2)[0];
    try {
        final FTPClient ftpClient = FTPUtils.getFTPClient(serverUrl, publishingProfile.getFtpUsername(), publishingProfile.getFtpPassword());
        for (final DeploymentResource externalResource : resources) {
            uploadResource(externalResource, ftpClient);
        }
    } catch (IOException e) {
        throw new AzureToolkitRuntimeException(e.getMessage(), e);
    }
}
Also used : DeploymentResource(com.microsoft.azure.maven.model.DeploymentResource) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IOException(java.io.IOException) PublishingProfile(com.microsoft.azure.toolkit.lib.appservice.model.PublishingProfile) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 5 with DeploymentResource

use of com.microsoft.azure.maven.model.DeploymentResource in project azure-maven-plugins by microsoft.

the class Deployment method getDefaultDeploymentConfiguration.

public static Deployment getDefaultDeploymentConfiguration(String deployType) {
    final Deployment result = new Deployment();
    final DeploymentResource resource = new DeploymentResource();
    resource.setDirectory(DEFAULT_DIRECTORY);
    resource.addInclude(String.format(DEFAULT_INCLUDE, StringUtils.firstNonBlank(deployType, DEFAULT_DEPLOYTYPE)));
    result.setResources(Collections.singletonList(resource));
    return result;
}
Also used : DeploymentResource(com.microsoft.azure.maven.model.DeploymentResource)

Aggregations

DeploymentResource (com.microsoft.azure.maven.model.DeploymentResource)5 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)2 MavenDockerCredentialProvider (com.microsoft.azure.maven.MavenDockerCredentialProvider)1 MavenArtifactUtils (com.microsoft.azure.maven.utils.MavenArtifactUtils)1 AbstractWebAppMojo (com.microsoft.azure.maven.webapp.AbstractWebAppMojo)1 WebAppConfiguration (com.microsoft.azure.maven.webapp.WebAppConfiguration)1 Deployment (com.microsoft.azure.maven.webapp.configuration.Deployment)1 DeploymentSlotConfig (com.microsoft.azure.maven.webapp.configuration.DeploymentSlotConfig)1 MavenRuntimeConfig (com.microsoft.azure.maven.webapp.configuration.MavenRuntimeConfig)1 AppServiceConfig (com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig)1 RuntimeConfig (com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig)1 DeployType (com.microsoft.azure.toolkit.lib.appservice.model.DeployType)1 JavaVersion (com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion)1 OperatingSystem (com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem)1 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)1 PublishingProfile (com.microsoft.azure.toolkit.lib.appservice.model.PublishingProfile)1 Runtime (com.microsoft.azure.toolkit.lib.appservice.model.Runtime)1 WebAppArtifact (com.microsoft.azure.toolkit.lib.appservice.model.WebAppArtifact)1 WebContainer (com.microsoft.azure.toolkit.lib.appservice.model.WebContainer)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1