Search in sources :

Example 6 with Blob

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);
}
Also used : Blob(de.mirkosertic.gameengine.web.html5.Blob) JSObject(org.teavm.jso.JSObject) JSString(org.teavm.jso.core.JSString)

Example 7 with Blob

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()));
    }
}
Also used : Blob(sirius.biz.storage.layer2.Blob) OutputStream(java.io.OutputStream) Watch(sirius.kernel.commons.Watch) HandledException(sirius.kernel.health.HandledException)

Example 8 with Blob

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;
}
Also used : Blob(sirius.biz.storage.layer2.Blob)

Example 9 with Blob

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);
    }
}
Also used : Blob(sirius.biz.storage.layer2.Blob) BlobStorageSpace(sirius.biz.storage.layer2.BlobStorageSpace) HandledException(sirius.kernel.health.HandledException)

Example 10 with Blob

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();
    });
}
Also used : Wait(sirius.kernel.commons.Wait) Part(sirius.kernel.di.std.Part) FileHandle(sirius.biz.storage.layer1.FileHandle) URL(java.net.URL) BlobConversionEvent(sirius.biz.storage.layer2.variants.BlobConversionEvent) Explain(sirius.kernel.commons.Explain) Processor(sirius.kernel.commons.Processor) EventRecorder(sirius.biz.analytics.events.EventRecorder) NLS(sirius.kernel.nls.NLS) Streams(sirius.kernel.commons.Streams) Duration(java.time.Duration) Locks(sirius.biz.locks.Locks) CacheManager(sirius.kernel.cache.CacheManager) ConversionEngine(sirius.biz.storage.layer2.variants.ConversionEngine) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) ObjectStorage(sirius.biz.storage.layer1.ObjectStorage) Tasks(sirius.kernel.async.Tasks) Objects(java.util.Objects) List(java.util.List) Extension(sirius.kernel.settings.Extension) Optional(java.util.Optional) Producer(sirius.kernel.commons.Producer) Exceptions(sirius.kernel.health.Exceptions) HandledException(sirius.kernel.health.HandledException) LocalDateTime(java.time.LocalDateTime) BlobVariant(sirius.biz.storage.layer2.variants.BlobVariant) Function(java.util.function.Function) ConfigValue(sirius.kernel.di.std.ConfigValue) ConversionProcess(sirius.biz.storage.layer2.variants.ConversionProcess) URLConnection(java.net.URLConnection) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) OutputStream(java.io.OutputStream) Strings(sirius.kernel.commons.Strings) KeyGenerator(sirius.db.KeyGenerator) MalformedURLException(java.net.MalformedURLException) Tuple(sirius.kernel.commons.Tuple) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Response(sirius.web.http.Response) Callback(sirius.kernel.commons.Callback) File(java.io.File) StorageUtils(sirius.biz.storage.util.StorageUtils) TimeUnit(java.util.concurrent.TimeUnit) Files(sirius.kernel.commons.Files) Cache(sirius.kernel.cache.Cache) UserContext(sirius.web.security.UserContext) ObjectStorageSpace(sirius.biz.storage.layer1.ObjectStorageSpace) InputStream(java.io.InputStream) FileHandle(sirius.biz.storage.layer1.FileHandle) BlobConversionEvent(sirius.biz.storage.layer2.variants.BlobConversionEvent) ConversionProcess(sirius.biz.storage.layer2.variants.ConversionProcess)

Aggregations

HashMap (java.util.HashMap)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time)6 Blob (org.flyte.api.v1.Blob)5 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)5 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int)5 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)5 Literal (org.flyte.api.v1.Literal)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)4