use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getTableEntities.
@NotNull
public List<TableEntity> getTableEntities(@NotNull StorageAccount storageAccount, @NotNull Table table, @NotNull String filter) throws AzureCmdException {
List<TableEntity> teList = new ArrayList<TableEntity>();
try {
CloudTableClient client = getCloudTableClient(storageAccount);
String tableName = table.getName();
CloudTable cloudTable = client.getTableReference(tableName);
TableQuery<DynamicTableEntity> tableQuery = TableQuery.from(DynamicTableEntity.class);
if (!filter.isEmpty()) {
tableQuery.where(filter);
}
TableRequestOptions tro = new TableRequestOptions();
tro.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata);
for (DynamicTableEntity dte : cloudTable.execute(tableQuery, tro, null)) {
teList.add(getTableEntity(tableName, dte));
}
return teList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Table Entity list", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createQueue.
@NotNull
public Queue createQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
CloudQueue cloudQueue = client.getQueueReference(queue.getName());
cloudQueue.createIfNotExists();
cloudQueue.downloadAttributes();
String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : "";
long approximateMessageCount = cloudQueue.getApproximateMessageCount();
queue.setUri(uri);
queue.setApproximateMessageCount(approximateMessageCount);
return queue;
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Queue", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class CreateProjectUtil method convert.
@NotNull
private static IFile convert(@NotNull File file) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath location = Path.fromOSString(file.getAbsolutePath());
IFile ifile = workspace.getRoot().getFileForLocation(location);
return ifile;
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class HDInsightHelperImpl method openItem.
private void openItem(@NotNull final Project project, @NotNull IClusterDetail myClusterDetail, @NotNull String uuid, @Nullable VirtualFile closeableFile) {
final LightVirtualFile virtualFile = new LightVirtualFile(myClusterDetail.getName() + ": Job View");
virtualFile.putUserData(JobViewEditorProvider.JOB_VIEW_KEY, myClusterDetail);
virtualFile.setFileType(new FileType() {
@NotNull
@Override
public String getName() {
return this.getClass().getName();
}
@NotNull
@Override
public String getDescription() {
return "job view dummy file";
}
@NotNull
@Override
public String getDefaultExtension() {
return "";
}
@Nullable
@Override
public Icon getIcon() {
return StreamUtil.getImageResourceFile(CommonConst.SPARK_JOBVIEW_ICONPATH);
}
@Override
public boolean isBinary() {
return true;
}
@Override
public boolean isReadOnly() {
return true;
}
@Nullable
@Override
public String getCharset(@NotNull VirtualFile virtualFile, @NotNull byte[] bytes) {
return "UTF8";
}
});
virtualFile.putUserData(JobViewEditorProvider.JOB_VIEW_UUID, uuid);
openItem(project, virtualFile, closeableFile);
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method downloadSelectedFile.
private void downloadSelectedFile(final File targetFile, final boolean open) {
final BlobFile fileSelection = getFileSelection();
if (fileSelection != null) {
Job job = new Job("Downloading blob...") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Downloading blob...", IProgressMonitor.UNKNOWN);
try {
if (!targetFile.exists()) {
if (!targetFile.createNewFile()) {
throw new IOException("File not created");
}
}
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(targetFile), 65536) {
private long runningCount = 0;
@Override
public synchronized void write(@NotNull byte[] bytes, int i, int i1) throws IOException {
super.write(bytes, i, i1);
runningCount += i1;
double progress = (double) runningCount / fileSelection.getSize();
monitor.worked((int) (100 * progress));
monitor.subTask(String.format("%s%% downloaded", (int) (progress * 100)));
}
};
try {
// public void run() {
try {
StorageClientSDKManager.getManager().downloadBlobFileContent(connectionString, fileSelection, bufferedOutputStream);
if (open && targetFile.exists()) {
try {
final Process p;
Runtime runtime = Runtime.getRuntime();
p = runtime.exec(new String[] { "open", "-R", targetFile.getName() }, null, targetFile.getParentFile());
InputStream errorStream = p.getErrorStream();
String errResponse = new String(IOUtils.readFully(errorStream, -1, true));
if (p.waitFor() != 0) {
throw new Exception(errResponse);
}
} catch (Exception e) {
monitor.setTaskName("Error opening file");
monitor.subTask(e.getMessage());
}
// Desktop.getDesktop().open(targetFile);
}
} catch (AzureCmdException e) {
Throwable connectionFault = e.getCause().getCause();
monitor.setTaskName("Error downloading Blob");
monitor.subTask((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : connectionFault.getMessage());
return Status.CANCEL_STATUS;
}
} finally {
bufferedOutputStream.close();
}
} catch (IOException e) {
DefaultLoader.getUIHelper().showException("Error downloading Blob", e, "Error downloading Blob", false, true);
return Status.CANCEL_STATUS;
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
}
Aggregations