Search in sources :

Example 1 with BindingEnum

use of com.microsoft.azure.toolkit.lib.legacy.function.bindings.BindingEnum in project azure-tools-for-java by Microsoft.

the class FunctionRunState method prepareStagingFolder.

@AzureOperation(name = "function.prepare_staging_folder_detail", params = { "stagingFolder.getName()", "this.functionRunConfiguration.getFuncPath()" }, type = AzureOperation.Type.SERVICE)
private void prepareStagingFolder(File stagingFolder, RunProcessHandler processHandler, @NotNull final Operation operation) throws Exception {
    AzureTaskManager.getInstance().read(() -> {
        final Path hostJsonPath = FunctionUtils.getDefaultHostJson(project);
        final Path localSettingsJson = Paths.get(functionRunConfiguration.getLocalSettingsJsonPath());
        final PsiMethod[] methods = FunctionUtils.findFunctionsByAnnotation(functionRunConfiguration.getModule());
        final Path folder = stagingFolder.toPath();
        try {
            Map<String, FunctionConfiguration> configMap = FunctionUtils.prepareStagingFolder(folder, hostJsonPath, functionRunConfiguration.getModule(), methods);
            operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, StringUtils.join(FunctionUtils.getFunctionBindingList(configMap), ","));
            final Map<String, String> appSettings = FunctionUtils.loadAppSettingsFromSecurityStorage(functionRunConfiguration.getAppSettingsKey());
            FunctionUtils.copyLocalSettingsToStagingFolder(folder, localSettingsJson, appSettings);
            final Set<BindingEnum> bindingClasses = getFunctionBindingEnums(configMap);
            if (isInstallingExtensionNeeded(bindingClasses, processHandler)) {
                installProcess = getRunFunctionCliExtensionInstallProcessBuilder(stagingFolder).start();
            }
        } catch (AzureExecutionException | IOException e) {
            final String error = String.format("failed prepare staging folder[%s]", folder);
            throw new AzureToolkitRuntimeException(error, e);
        }
    });
    if (installProcess != null) {
        readInputStreamByLines(installProcess.getErrorStream(), inputLine -> {
            if (processHandler.isProcessRunning()) {
                processHandler.println(inputLine, ProcessOutputTypes.STDERR);
            }
        });
        readInputStreamByLines(installProcess.getInputStream(), inputLine -> {
            if (processHandler.isProcessRunning()) {
                processHandler.setText(inputLine);
            }
        });
        int exitCode = installProcess.waitFor();
        if (exitCode != 0) {
            throw new AzureExecutionException(message("function.run.error.installFuncFailed"));
        }
    }
}
Also used : Path(java.nio.file.Path) BindingEnum(com.microsoft.azure.toolkit.lib.legacy.function.bindings.BindingEnum) PsiMethod(com.intellij.psi.PsiMethod) FunctionConfiguration(com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IOException(java.io.IOException) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)1 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)1 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)1 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)1 BindingEnum (com.microsoft.azure.toolkit.lib.legacy.function.bindings.BindingEnum)1 FunctionConfiguration (com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1