use of com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration in project azure-tools-for-java by Microsoft.
the class FunctionUtils method prepareStagingFolder.
@AzureOperation(name = "function.prepare_staging_folder", type = AzureOperation.Type.TASK)
public static Map<String, FunctionConfiguration> prepareStagingFolder(Path stagingFolder, Path hostJson, Module module, PsiMethod[] methods) throws AzureExecutionException, IOException {
final Map<String, FunctionConfiguration> configMap = generateConfigurations(methods);
if (stagingFolder.toFile().isDirectory()) {
FileUtils.cleanDirectory(stagingFolder.toFile());
}
final Path jarFile = JarUtils.buildJarFileToStagingPath(stagingFolder.toString(), module);
final String scriptFilePath = "../" + jarFile.getFileName().toString();
configMap.values().forEach(config -> config.setScriptFile(scriptFilePath));
for (final Map.Entry<String, FunctionConfiguration> config : configMap.entrySet()) {
if (StringUtils.isNotBlank(config.getKey())) {
final File functionJsonFile = Paths.get(stagingFolder.toString(), config.getKey(), FUNCTION_JSON).toFile();
writeFunctionJsonFile(functionJsonFile, config.getValue());
}
}
final File hostJsonFile = new File(stagingFolder.toFile(), "host.json");
copyFilesWithDefaultContent(hostJson, hostJsonFile, DEFAULT_HOST_JSON);
final List<File> jarFiles = new ArrayList<>();
OrderEnumerator.orderEntries(module).productionOnly().forEachLibrary(lib -> {
if (StringUtils.isNotEmpty(lib.getName()) && ArrayUtils.contains(lib.getName().split("\\:"), FUNCTION_JAVA_LIBRARY_ARTIFACT_ID)) {
return true;
}
if (lib != null) {
for (final VirtualFile virtualFile : lib.getFiles(OrderRootType.CLASSES)) {
final File file = new File(stripExtraCharacters(virtualFile.getPath()));
if (file.exists()) {
jarFiles.add(file);
}
}
}
return true;
});
final File libFolder = new File(stagingFolder.toFile(), "lib");
for (final File file : jarFiles) {
FileUtils.copyFileToDirectory(file, libFolder);
}
return configMap;
}
use of com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration in project azure-tools-for-java by Microsoft.
the class FunctionUtils method generateConfiguration.
private static FunctionConfiguration generateConfiguration(PsiMethod method) throws AzureExecutionException {
final FunctionConfiguration config = new FunctionConfiguration();
final List<Binding> bindings = new ArrayList<>();
processParameterAnnotations(method, bindings);
processMethodAnnotations(method, bindings);
patchStorageBinding(method, bindings);
config.setEntryPoint(method.getContainingClass().getQualifiedName() + "." + method.getName());
// Todo: add set bindings method in tools-common
config.setBindings(bindings);
return config;
}
use of com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration in project azure-tools-for-java by Microsoft.
the class FunctionDeploymentState method prepareStagingFolder.
@AzureOperation(name = "function.prepare_staging_folder_detail", params = { "stagingFolder.getName()", "this.deployModel.getFunctionAppConfig().getName()" }, type = AzureOperation.Type.TASK)
private void prepareStagingFolder(File stagingFolder, RunProcessHandler processHandler, @NotNull final Operation operation) {
AzureTaskManager.getInstance().read(() -> {
final Path hostJsonPath = FunctionUtils.getDefaultHostJson(project);
final PsiMethod[] methods = FunctionUtils.findFunctionsByAnnotation(functionDeployConfiguration.getModule());
final Path folder = stagingFolder.toPath();
try {
final Map<String, FunctionConfiguration> configMap = FunctionUtils.prepareStagingFolder(folder, hostJsonPath, functionDeployConfiguration.getModule(), methods);
operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, StringUtils.join(FunctionUtils.getFunctionBindingList(configMap), ","));
} catch (final AzureExecutionException | IOException e) {
final String error = String.format("failed prepare staging folder[%s]", folder);
throw new AzureToolkitRuntimeException(error, e);
}
});
}
use of com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration in project azure-tools-for-java by Microsoft.
the class FunctionUtils method generateConfigurations.
private static Map<String, FunctionConfiguration> generateConfigurations(final PsiMethod[] methods) throws AzureExecutionException {
final Map<String, FunctionConfiguration> configMap = new HashMap<>();
for (final PsiMethod method : methods) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(method, FunctionUtils.AZURE_FUNCTION_ANNOTATION_CLASS);
final String functionName = AnnotationUtil.getDeclaredStringAttributeValue(annotation, "value");
configMap.put(functionName, generateConfiguration(method));
}
return configMap;
}
use of com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration 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"));
}
}
}
Aggregations