use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class FunctionRunState method validateFunctionRuntime.
@AzureOperation(name = "function.validate_runtime", params = { "this.functionRunConfiguration.getFuncPath()" }, type = AzureOperation.Type.TASK)
private void validateFunctionRuntime(RunProcessHandler processHandler) {
try {
final String funcPath = functionRunConfiguration.getFuncPath();
if (StringUtils.isEmpty(funcPath)) {
throw new AzureToolkitRuntimeException(message("function.run.error.runtimeNotFound"));
}
final ComparableVersion funcVersion = getFuncVersion();
if (funcVersion == null) {
throw new AzureToolkitRuntimeException(message("function.run.error.runtimeNotFound"));
}
final ComparableVersion javaVersion = getJavaVersion();
if (javaVersion == null) {
processHandler.setText(message("function.run.error.getJavaVersionFailed"));
return;
}
if (javaVersion.compareTo(JAVA_9) < 0) {
// No need validate function host version within java 8 or earlier
return;
}
final ComparableVersion minimumVersion = funcVersion.compareTo(FUNC_3) >= 0 ? MINIMUM_JAVA_9_SUPPORTED_VERSION : MINIMUM_JAVA_9_SUPPORTED_VERSION_V2;
if (funcVersion.compareTo(minimumVersion) < 0) {
throw new AzureToolkitRuntimeException(message("function.run.error.funcOutOfDate"));
}
} catch (IOException e) {
throw new AzureToolkitRuntimeException(message("function.run.error.validateRuntimeFailed", e.getMessage()));
}
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class FunctionRunState method getJavaVersion.
// Get java runtime version following the strategy of function core tools
// Get java version of JAVA_HOME first, fall back to use PATH if JAVA_HOME not exists
@AzureOperation(name = "function.validate_jre", type = AzureOperation.Type.TASK)
private static ComparableVersion getJavaVersion() throws IOException {
final String javaHome = System.getenv("JAVA_HOME");
final File javaFile = StringUtils.isEmpty(javaHome) ? null : Paths.get(javaHome, "bin", "java").toFile();
final String executeFolder = javaFile == null ? null : javaFile.getParentFile().getAbsolutePath();
final String command = javaFile == null ? "java" : javaFile.getAbsolutePath();
final String javaVersion = CommandUtils.exec("java -version", executeFolder, true);
if (StringUtils.isEmpty(javaVersion)) {
return null;
}
final Matcher matcher = JAVA_VERSION_PATTERN.matcher(javaVersion);
return matcher.find() ? new ComparableVersion(matcher.group(1)) : null;
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation 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"));
}
}
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class FunctionDeploymentState method executeSteps.
@Nullable
@Override
@AzureOperation(name = "function.deploy.state", type = AzureOperation.Type.ACTION)
public IFunctionApp executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws IOException {
final FunctionDeploymentMessenger messenger = new FunctionDeploymentMessenger(processHandler);
AzureMessager.getContext().setMessager(messenger);
final IFunctionApp functionApp;
if (StringUtils.isEmpty(functionDeployConfiguration.getFunctionId())) {
functionApp = createFunctionApp(processHandler);
} else {
functionApp = Azure.az(AzureAppService.class).subscription(functionDeployConfiguration.getSubscriptionId()).functionApp(functionDeployConfiguration.getFunctionId());
updateApplicationSettings(functionApp);
}
stagingFolder = FunctionUtils.getTempStagingFolder();
prepareStagingFolder(stagingFolder, processHandler, operation);
// deploy function to Azure
FunctionAppService.getInstance().deployFunctionApp(functionApp, stagingFolder);
// list triggers after deployment
listHTTPTriggerUrls(functionApp);
operation.trackProperties(AzureTelemetry.getActionContext().getProperties());
return functionApp;
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class CreateFunctionAppAction method actionPerformed.
@Override
@AzureOperation(name = "function.create", type = AzureOperation.Type.ACTION)
public void actionPerformed(NodeActionEvent e) {
final Project project = (Project) functionModule.getProject();
AzureSignInAction.requireSignedIn(project, () -> this.openDialog(project, null));
}
Aggregations