Search in sources :

Example 1 with Options

use of com.walmartlabs.concord.process.loader.model.Options in project concord by walmartlabs.

the class EffectiveProcessDefinitionProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessDefinition pd = payload.getHeader(Payload.PROJECT_DEFINITION);
    if (pd == null) {
        return chain.process(payload);
    }
    Options opts = Options.builder().instanceId(payload.getProcessKey().getInstanceId()).parentInstanceId(payload.getHeader(Payload.PARENT_INSTANCE_ID)).configuration(sanitizeConfiguration(payload.getHeader(Payload.CONFIGURATION, Collections.emptyMap()))).activeProfiles(payload.getHeader(Payload.ACTIVE_PROFILES, Collections.emptyList())).build();
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        pd.serialize(opts, out);
        byte[] bytes = out.toByteArray();
        if (bytes.length == 0) {
            return chain.process(payload);
        }
        stateManager.tx(tx -> {
            stateManager.deleteFile(tx, payload.getProcessKey(), EFFECTIVE_YAML_PATH);
            stateManager.insert(tx, payload.getProcessKey(), EFFECTIVE_YAML_PATH, bytes);
        });
    } catch (Exception e) {
        log.warn("process ['{}'] -> error: {}", payload.getProcessKey(), e.getMessage());
        throw new ProcessException(payload.getProcessKey(), "Error while processing effective concord.yml: " + e.getMessage(), e);
    }
    return chain.process(payload);
}
Also used : Options(com.walmartlabs.concord.process.loader.model.Options) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProcessException(com.walmartlabs.concord.server.process.ProcessException)

Aggregations

Options (com.walmartlabs.concord.process.loader.model.Options)1 ProcessDefinition (com.walmartlabs.concord.process.loader.model.ProcessDefinition)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1