Search in sources :

Example 1 with GradleFunctionContext

use of com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext in project azure-gradle-plugins by microsoft.

the class DeployTask method deploy.

@TaskAction
@AzureOperation(name = "functionapp.deploy_app", type = AzureOperation.Type.ACTION)
public void deploy() throws GradleException {
    try {
        ProxyManager.getInstance().applyProxy();
        TelemetryAgent.getInstance().addDefaultProperty(PROXY, String.valueOf(ProxyManager.getInstance().isProxyEnabled()));
        TelemetryAgent.getInstance().trackTaskStart(this.getClass());
        final GradleFunctionContext ctx = new GradleFunctionContext(getProject(), this.getFunctionsExtension());
        TelemetryAgent.getInstance().addDefaultProperties(ctx.getTelemetryProperties());
        final DeployHandler deployHandler = new DeployHandler(ctx);
        deployHandler.execute();
        TelemetryAgent.getInstance().trackTaskSuccess(this.getClass());
    } catch (final Exception e) {
        AzureMessager.getMessager().error(e);
        TelemetryAgent.getInstance().traceException(this.getClass(), e);
        throw new GradleException(DEPLOY_FAILURE + e.getMessage(), e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) GradleFunctionContext(com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext) GradleException(org.gradle.api.GradleException) DeployHandler(com.microsoft.azure.plugin.functions.gradle.handler.DeployHandler) TaskAction(org.gradle.api.tasks.TaskAction) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 2 with GradleFunctionContext

use of com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext in project azure-gradle-plugins by microsoft.

the class LocalRunTask method exec.

@TaskAction
@Override
@AzureOperation(name = "functionapp.run", type = AzureOperation.Type.ACTION)
public void exec() {
    try {
        TelemetryAgent.getInstance().trackTaskStart(this.getClass());
        final GradleFunctionContext ctx = new GradleFunctionContext(getProject(), this.getFunctionsExtension());
        final String cliExec = FunctionCliResolver.resolveFunc();
        if (StringUtils.isEmpty(cliExec)) {
            throw new GradleException(FUNC_CORE_CLI_NOT_FOUND);
        }
        final String stagingFolder = ctx.getDeploymentStagingDirectoryPath();
        FunctionUtils.checkStagingDirectory(stagingFolder);
        if (BooleanUtils.isTrue(this.enableDebug) || StringUtils.isNotEmpty(ctx.getLocalDebugConfig())) {
            this.commandLine(cliExec, "host", "start", "--language-worker", "--", getDebugJvmArgument(ctx.getLocalDebugConfig()));
        } else {
            this.commandLine(cliExec, "host", "start");
        }
        this.setWorkingDir(new File(stagingFolder));
        this.setIgnoreExitValue(true);
        super.exec();
        final int code = this.getExecResult().getExitValue();
        for (final Long validCode : CommandUtils.getValidReturnCodes()) {
            if (validCode != null && validCode.intValue() == code) {
                TelemetryAgent.getInstance().trackTaskSuccess(this.getClass());
                return;
            }
        }
        throw new GradleException(RUN_FUNCTIONS_FAILURE);
    } catch (Exception e) {
        TelemetryAgent.getInstance().traceException(this.getClass(), e);
        throw new GradleException("Cannot run functions locally due to error:" + e.getMessage(), e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) GradleFunctionContext(com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext) File(java.io.File) GradleException(org.gradle.api.GradleException) TaskAction(org.gradle.api.tasks.TaskAction) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 3 with GradleFunctionContext

use of com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext in project azure-gradle-plugins by microsoft.

the class PackageTask method build.

@TaskAction
@AzureOperation(name = "functionapp.package", type = AzureOperation.Type.ACTION)
public void build() throws GradleException {
    try {
        TelemetryAgent.getInstance().trackTaskStart(this.getClass());
        final GradleFunctionContext ctx = new GradleFunctionContext(getProject(), this.getFunctionsExtension());
        TelemetryAgent.getInstance().addDefaultProperties(ctx.getTelemetryProperties());
        final File stagingFolder = new File(ctx.getDeploymentStagingDirectoryPath());
        // package task will start from a empty staging folder
        if (stagingFolder.exists()) {
            FileUtils.cleanDirectory(stagingFolder);
        } else {
            stagingFolder.mkdirs();
        }
        final PackageHandler packageHandler = new PackageHandler(ctx.getProject(), ctx.getDeploymentStagingDirectoryPath());
        packageHandler.execute();
        TelemetryAgent.getInstance().trackTaskSuccess(this.getClass());
    } catch (Exception e) {
        TelemetryAgent.getInstance().traceException(this.getClass(), e);
        throw new GradleException(PACKAGE_FAILURE + e.getMessage(), e);
    }
}
Also used : PackageHandler(com.microsoft.azure.plugin.functions.gradle.handler.PackageHandler) GradleException(org.gradle.api.GradleException) GradleFunctionContext(com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext) File(java.io.File) GradleException(org.gradle.api.GradleException) TaskAction(org.gradle.api.tasks.TaskAction) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 4 with GradleFunctionContext

use of com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext in project azure-gradle-plugins by microsoft.

the class PackageZipTask method buildZip.

@TaskAction
public void buildZip() throws GradleException, IOException {
    try {
        TelemetryAgent.getInstance().trackTaskStart(this.getClass());
        final GradleFunctionContext ctx = new GradleFunctionContext(getProject(), this.getFunctionsExtension());
        FunctionUtils.checkStagingDirectory(ctx.getDeploymentStagingDirectoryPath());
        final File zipFile = new File(ctx.getDeploymentStagingDirectoryPath() + ".zip");
        ZipUtil.pack(new File(ctx.getDeploymentStagingDirectoryPath()), zipFile);
        ZipUtil.removeEntry(zipFile, PackageHandler.LOCAL_SETTINGS_JSON);
        AzureMessager.getMessager().info("Build zip from staging folder successfully: " + zipFile.getAbsolutePath());
        TelemetryAgent.getInstance().trackTaskSuccess(this.getClass());
    } catch (Exception e) {
        TelemetryAgent.getInstance().traceException(this.getClass(), e);
        throw new GradleException(PACKAGE_ZIP_FAILURE + e.getMessage(), e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) GradleFunctionContext(com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext) File(java.io.File) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

GradleFunctionContext (com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext)4 GradleException (org.gradle.api.GradleException)4 TaskAction (org.gradle.api.tasks.TaskAction)4 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)3 File (java.io.File)3 DeployHandler (com.microsoft.azure.plugin.functions.gradle.handler.DeployHandler)1 PackageHandler (com.microsoft.azure.plugin.functions.gradle.handler.PackageHandler)1 IOException (java.io.IOException)1