use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.
the class ClusterDetail method getDefaultStorageAccount.
@Nullable
private IHDIStorageAccount getDefaultStorageAccount(Map<String, String> coresiteMap, ClusterIdentity clusterIdentity) throws HDIException {
String defaultStorageRootPath = getDefaultStorageRootPath();
if (defaultStorageRootPath == null) {
throw new HDIException("Failed to get default storage root path");
}
StorageAccountType storageType = StorageAccountType.parseUri(URI.create(defaultStorageRootPath));
switch(storageType) {
case ADLS:
return new ADLSStorageAccount(this, true, clusterIdentity, URI.create(defaultStorageRootPath));
case BLOB:
WasbUri wasbUri = WasbUri.parse(defaultStorageRootPath);
String storageAccountName = wasbUri.getStorageAccount() + ".blob." + wasbUri.getEndpointSuffix();
String defaultContainerName = wasbUri.getContainer();
String defaultStorageAccountKey = StorageAccountKeyPrefix + storageAccountName;
String storageAccountKey = null;
if (coresiteMap.containsKey(defaultStorageAccountKey)) {
storageAccountKey = coresiteMap.get(defaultStorageAccountKey);
}
if (storageAccountKey == null) {
return null;
}
return new HDStorageAccount(this, storageAccountName, storageAccountKey, true, defaultContainerName);
case ADLSGen2:
AbfsUri abfsUri = AbfsUri.parse(defaultStorageRootPath);
String accountName = abfsUri.getAccountName();
String fileSystem = abfsUri.getFileSystem();
return new ADLSGen2StorageAccount(this, accountName, null, true, fileSystem, abfsUri.getUri().getScheme());
default:
return null;
}
}
use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.
the class HttpObservable method request.
/*
* Core request
*/
public Observable<CloseableHttpResponse> request(@NotNull final HttpRequestBase httpRequest, @Nullable final HttpEntity entity, final List<NameValuePair> parameters, final List<Header> addOrReplaceHeaders) {
return Observable.fromCallable(() -> {
URIBuilder builder = new URIBuilder(httpRequest.getURI());
// Add parameters
builder.setParameters(getDefaultParameters());
Optional.ofNullable(parameters).filter(pairs -> !pairs.isEmpty()).ifPresent(builder::addParameters);
httpRequest.setURI(builder.build());
// Set the default headers and update Headers
httpRequest.setHeaders(getDefaultHeaders());
Optional.ofNullable(addOrReplaceHeaders).ifPresent(headers -> headers.forEach(httpRequest::setHeader));
// Set entity for non-entity
if (httpRequest instanceof HttpEntityEnclosingRequestBase && entity != null) {
((HttpEntityEnclosingRequestBase) httpRequest).setEntity(entity);
// Update the content type by entity
httpRequest.setHeader(entity.getContentType());
}
return getHttpClient().execute(httpRequest, getHttpContext());
});
}
use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.
the class SparkBatchJobRunner method doExecute.
@Nullable
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
final SparkBatchRemoteRunProfileState submissionState = (SparkBatchRemoteRunProfileState) state;
final SparkSubmitModel submitModel = submissionState.getSubmitModel();
final Project project = submitModel.getProject();
// Prepare the run table console view UI
final SparkJobLogConsoleView jobOutputView = new SparkJobLogConsoleView(project);
final String artifactPath = submitModel.getArtifactPath().orElse(null);
assert artifactPath != null : "artifactPath should be checked in LivySparkBatchJobRunConfiguration::checkSubmissionConfigurationBeforeRun";
// To address issue https://github.com/microsoft/azure-tools-for-java/issues/4021.
// In this issue, when user click rerun button, we are still using the legacy ctrlSubject which has already sent
// "onComplete" message when the job is done in the previous time. To avoid this issue, We clone a new Spark
// batch job instance to re-initialize everything in the object.
final ISparkBatchJob sparkBatch = submissionState.getSparkBatch().clone();
final PublishSubject<SparkLogLine> ctrlSubject = (PublishSubject<SparkLogLine>) sparkBatch.getCtrlSubject();
final SparkBatchJobRemoteProcess remoteProcess = new SparkBatchJobRemoteProcess(new IdeaSchedulers(project), sparkBatch, artifactPath, submitModel.getSubmissionParameter().getMainClassName(), ctrlSubject);
final SparkBatchJobRunProcessHandler processHandler = new SparkBatchJobRunProcessHandler(remoteProcess, "Package and deploy the job to Spark cluster", null);
// After attaching, the console view can read the process inputStreams and display them
jobOutputView.attachToProcess(processHandler);
remoteProcess.start();
final Operation operation = environment.getUserData(TelemetryKeys.OPERATION);
// After we define a new AnAction class, IntelliJ will construct a new AnAction instance for us.
// Use one action instance can keep behaviours like isEnabled() consistent
final SparkBatchJobDisconnectAction disconnectAction = (SparkBatchJobDisconnectAction) ActionManager.getInstance().getAction("Actions.SparkJobDisconnect");
disconnectAction.init(remoteProcess, operation);
sendTelemetryForParameters(submitModel, operation);
final ExecutionResult result = new DefaultExecutionResult(jobOutputView, processHandler, Separator.getInstance(), disconnectAction);
submissionState.setExecutionResult(result);
final ConsoleView consoleView = jobOutputView.getSecondaryConsoleView();
submissionState.setConsoleView(consoleView);
addConsoleViewFilter(remoteProcess.getSparkJob(), consoleView);
submissionState.setRemoteProcessCtrlLogHandler(processHandler);
ctrlSubject.subscribe(messageWithType -> {
}, err -> disconnectAction.setEnabled(false), () -> disconnectAction.setEnabled(false));
return super.doExecute(state, environment);
}
use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.
the class UIHelperImpl method getOpenedFile.
@Nullable
@Override
public <T extends StorageServiceTreeItem> Object getOpenedFile(@NotNull Object projectObject, @NotNull String accountName, @NotNull T item) {
FileEditorManager fileEditorManager = FileEditorManager.getInstance((Project) projectObject);
for (VirtualFile editedFile : fileEditorManager.getOpenFiles()) {
T editedItem = editedFile.getUserData((Key<T>) name2Key.get(item.getClass()));
StorageAccount editedStorageAccount = editedFile.getUserData(STORAGE_KEY);
ClientStorageAccount editedClientStorageAccount = editedFile.getUserData(CLIENT_STORAGE_KEY);
if (((editedStorageAccount != null && editedStorageAccount.name().equals(accountName)) || (editedClientStorageAccount != null && editedClientStorageAccount.getName().equals(accountName))) && editedItem != null && editedItem.getName().equals(item.getName())) {
return editedFile;
}
}
return null;
}
use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.
the class CreateFunctionAppAction method openDialog.
@AzureOperation(name = "function.open_creation_dialog", type = AzureOperation.Type.ACTION)
private void openDialog(final Project project, @Nullable final FunctionAppConfig data) {
final FunctionAppCreationDialog dialog = new FunctionAppCreationDialog(project);
if (Objects.nonNull(data)) {
dialog.setData(data);
}
dialog.setOkActionListener((config) -> {
dialog.close();
this.createFunctionApp(config).subscribe(functionApp -> {
}, (error) -> {
final String title = String.format("Reopen dialog \"%s\"", dialog.getTitle());
final Consumer<Object> act = t -> AzureTaskManager.getInstance().runLater("open dialog", () -> this.openDialog(project, config));
final Action<?> action = new Action<>(act, new ActionView.Builder(title));
AzureMessager.getMessager().error(error, null, action);
});
});
dialog.show();
}
Aggregations