use of sirius.biz.storage.layer2.Blob in project GameComposer by mirkosertic.
the class EditorState method saveGame.
public Promise<File, String> saveGame() {
JSObject theJSForm = TeaVMMap.toJS(loadedGame.serialize());
String theJSON = TeaVMMap.stringifyPretty(theJSForm);
Blob theBlob = Blob.createJSONBlob(JSString.valueOf(theJSON));
return resourceAccessor.persistFile("/game.json", theBlob);
}
use of sirius.biz.storage.layer2.Blob in project sirius-biz by scireum.
the class JupiterSync method executeDataProvider.
private void executeDataProvider(ProcessContext processContext, JupiterDataProvider provider) {
Watch watch = Watch.start();
processContext.log(ProcessLog.info().withFormattedMessage("Executing data provider: %s", provider.getName()));
Blob blob = blobStorage.getSpace(localRepoSpaceName).findOrCreateByPath(tenants.getTenantUserManager().getSystemTenantId(), provider.getFilename());
try (OutputStream out = blob.createOutputStream(Files.getFilenameAndExtension(provider.getFilename()))) {
provider.execute(out);
processContext.log(ProcessLog.info().withFormattedMessage("Creating '%s' took %s...", provider.getFilename(), watch.duration()));
} catch (Exception e) {
processContext.log(ProcessLog.error().withMessage(Exceptions.handle().to(Jupiter.LOG).error(e).withSystemErrorMessage("Failed to execute data provider %s: %s (%s)", provider.getName()).handle().getMessage()));
}
}
use of sirius.biz.storage.layer2.Blob in project sirius-biz by scireum.
the class TmpRoot method unwrapBlob.
private VirtualFile unwrapBlob(VirtualFile parent, String name) {
Blob blob = parent.as(Blob.class);
if (!Strings.areEqual(blob.getFilename(), name)) {
return null;
}
MutableVirtualFile result = new MutableVirtualFile(parent, blob.getFilename());
result.markAsExistingFile();
result.withInputStreamSupplier(ignored -> blob.createInputStream());
result.withFileHandleSupplier(ignored -> blob.download().orElse(null));
result.withCanDeleteHandler(MutableVirtualFile.CONSTANT_TRUE);
result.withDeleteHandler(ignored -> {
blob.delete();
return true;
});
result.withSizeSupplier(ignored -> blob.getSize());
return result;
}
use of sirius.biz.storage.layer2.Blob in project sirius-biz by scireum.
the class JobStartingRoot method uploadAndTrigger.
/**
* Creates an <tt>OutputStream</tt> which triggers the given job with the given parameters once the stream is closed.
*
* @param jobToRun the job to actually run
* @param parameterProvider permits to control the parameter values for the job (the file is automatically used as
* first {@link FileParameter} of the job)
* @param filename the actual filename of the file being processed
* @return an output stream which triggers the job once the stream is closed
*/
protected OutputStream uploadAndTrigger(JobFactory jobToRun, Function<String, Value> parameterProvider, String filename) {
try {
BlobStorageSpace temporaryStorageSpace = blobStorage.getSpace(TmpRoot.TMP_SPACE);
Blob buffer = temporaryStorageSpace.createTemporaryBlob(UserContext.getCurrentUser().getTenantId());
return buffer.createOutputStream(() -> {
if (buffer.getSize() > 0) {
temporaryStorageSpace.markAsUsed(buffer);
trigger(jobToRun, parameterProvider, buffer, filename);
} else {
buffer.delete();
}
}, filename);
} catch (Exception e) {
throw Exceptions.handle(e);
}
}
use of sirius.biz.storage.layer2.Blob in project sirius-biz by scireum.
the class BasicBlobStorageSpace method invokeConversionPipelineAsync.
/**
* Spawns a thread which will actually invoke the appropriate conversion pipeline.
*
* @param blob the blob for which the variant is to be created
* @param variant the variant to generate
*/
private void invokeConversionPipelineAsync(B blob, V variant) {
ConversionProcess conversionProcess = new ConversionProcess(blob, variant.getVariantName());
conversionEngine.performConversion(conversionProcess).onSuccess(ignored -> {
try (FileHandle automaticHandle = conversionProcess.getResultFileHandle()) {
String physicalKey = keyGenerator.generateId();
conversionProcess.upload(() -> {
getPhysicalSpace().upload(physicalKey, automaticHandle.getFile());
});
markConversionSuccess(variant, physicalKey, conversionProcess);
eventRecorder.record(new BlobConversionEvent().withConversionProcess(conversionProcess).withOutputFile(automaticHandle));
}
}).onFailure(conversionException -> {
markConversionFailure(variant, conversionProcess);
eventRecorder.record(new BlobConversionEvent().withConversionProcess(conversionProcess).withConversionError(conversionException));
throw Exceptions.handle().error(conversionException).to(StorageUtils.LOG).withSystemErrorMessage("Layer 2/Conversion: Failed to create %s (%s) of %s (%s): %s (%s)", variant.getVariantName(), variant.getIdAsString(), blob.getBlobKey(), blob.getFilename()).handle();
});
}
Aggregations