Search in sources :

Example 1 with DependencyManager

use of com.walmartlabs.concord.dependencymanager.DependencyManager in project concord by walmartlabs.

the class Run method call.

@Override
public Integer call() throws Exception {
    sourceDir = sourceDir.normalize().toAbsolutePath();
    Path targetDir;
    if (Files.isRegularFile(sourceDir)) {
        Path src = sourceDir.toAbsolutePath();
        System.out.println("Running a single Concord file: " + src);
        targetDir = Files.createTempDirectory("payload");
        Files.copy(src, targetDir.resolve("concord.yml"), StandardCopyOption.REPLACE_EXISTING);
    } else if (Files.isDirectory(sourceDir)) {
        targetDir = sourceDir.resolve("target");
        if (cleanup && Files.exists(targetDir)) {
            if (verbose) {
                System.out.println("Cleaning target directory");
            }
            IOUtils.deleteRecursively(targetDir);
        }
        // copy everything into target except target
        IOUtils.copy(sourceDir, targetDir, "^target$", new CopyNotifier(verbose ? 0 : 100), StandardCopyOption.REPLACE_EXISTING);
    } else {
        throw new IllegalArgumentException("Not a directory or single Concord YAML file: " + sourceDir);
    }
    DependencyManager dependencyManager = initDependencyManager();
    ImportManager importManager = new ImportManagerFactory(dependencyManager, new CliRepositoryExporter(repoCacheDir), Collections.emptySet()).create();
    ProjectLoaderV2.Result loadResult;
    try {
        loadResult = new ProjectLoaderV2(importManager).load(targetDir, new CliImportsNormalizer(importsSource, verbose, defaultVersion), verbose ? new CliImportsListener() : null);
    } catch (ImportProcessingException e) {
        ObjectMapper om = new ObjectMapper();
        System.err.println("Error while processing import " + om.writeValueAsString(e.getImport()) + ": " + e.getMessage());
        return -1;
    } catch (Exception e) {
        System.err.println("Error while loading " + targetDir);
        e.printStackTrace();
        return -1;
    }
    ProcessDefinition processDefinition = loadResult.getProjectDefinition();
    UUID instanceId = UUID.randomUUID();
    if (verbose && !extraVars.isEmpty()) {
        System.out.println("Additional variables: " + extraVars);
    }
    if (verbose && !profiles.isEmpty()) {
        System.out.println("Active profiles: " + profiles);
    }
    ProcessConfiguration cfg = from(processDefinition.configuration()).entryPoint(entryPoint).instanceId(instanceId).build();
    RunnerConfiguration runnerCfg = RunnerConfiguration.builder().dependencies(new DependencyResolver(dependencyManager, verbose).resolveDeps(processDefinition)).debug(cfg.debug()).build();
    Map<String, Object> profileArgs = getProfilesArguments(processDefinition, profiles);
    Map<String, Object> args = ConfigurationUtils.deepMerge(cfg.arguments(), profileArgs, extraVars);
    if (verbose) {
        System.out.println("Process arguments: " + args);
    }
    args.put(Constants.Context.TX_ID_KEY, instanceId.toString());
    args.put(Constants.Context.WORK_DIR_KEY, targetDir.toAbsolutePath().toString());
    if (effectiveYaml) {
        Map<String, List<Step>> flows = new HashMap<>(processDefinition.flows());
        for (String ap : profiles) {
            Profile p = processDefinition.profiles().get(ap);
            if (p != null) {
                flows.putAll(p.flows());
            }
        }
        ProcessDefinition pd = ProcessDefinition.builder().from(processDefinition).configuration(ProcessDefinitionConfiguration.builder().from(processDefinition.configuration()).arguments(args).build()).flows(flows).imports(Imports.builder().build()).profiles(Collections.emptyMap()).build();
        ProjectSerializerV2 serializer = new ProjectSerializerV2();
        serializer.write(pd, System.out);
        return 0;
    }
    System.out.println("Starting...");
    Injector injector = new InjectorFactory(new WorkingDirectory(targetDir), runnerCfg, () -> cfg, new ProcessDependenciesModule(targetDir, runnerCfg.dependencies(), cfg.debug()), new CliServicesModule(secretStoreDir, targetDir, new VaultProvider(vaultDir, vaultId), dependencyManager)).create();
    Runner runner = injector.getInstance(Runner.class);
    if (cfg.debug()) {
        System.out.println("Available tasks: " + injector.getInstance(TaskProviders.class).names());
    }
    try {
        runner.start(cfg, processDefinition, args);
    } catch (Exception e) {
        if (verbose) {
            System.err.print("Error: ");
            e.printStackTrace(System.err);
        } else {
            System.err.println("Error: " + e.getMessage());
        }
        return 1;
    }
    System.out.println("...done!");
    return 0;
}
Also used : ImportManager(com.walmartlabs.concord.imports.ImportManager) Runner(com.walmartlabs.concord.runtime.v2.runner.Runner) DependencyManager(com.walmartlabs.concord.dependencymanager.DependencyManager) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) Profile(com.walmartlabs.concord.runtime.v2.model.Profile) ProjectSerializerV2(com.walmartlabs.concord.runtime.v2.ProjectSerializerV2) ImmutableProcessConfiguration(com.walmartlabs.concord.runtime.v2.sdk.ImmutableProcessConfiguration) ProcessConfiguration(com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration) InjectorFactory(com.walmartlabs.concord.runtime.v2.runner.InjectorFactory) Injector(com.google.inject.Injector) RunnerConfiguration(com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration) ImportManagerFactory(com.walmartlabs.concord.imports.ImportManagerFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(java.nio.file.Path) WorkingDirectory(com.walmartlabs.concord.runtime.v2.sdk.WorkingDirectory) ImportProcessingException(com.walmartlabs.concord.imports.ImportProcessingException) ProcessDependenciesModule(com.walmartlabs.concord.runtime.v2.runner.guice.ProcessDependenciesModule) IOException(java.io.IOException) ImportProcessingException(com.walmartlabs.concord.imports.ImportProcessingException) ProjectLoaderV2(com.walmartlabs.concord.runtime.v2.ProjectLoaderV2) TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)

Example 2 with DependencyManager

use of com.walmartlabs.concord.dependencymanager.DependencyManager in project concord by walmartlabs.

the class CliServicesModule method configure.

@Override
protected void configure() {
    install(new BaseRunnerModule());
    bind(RunnerLogger.class).to(SimpleLogger.class);
    bind(SecretService.class).toInstance(new CliSecretService(workDir, secretStoreDir, vaultProvider));
    bind(DockerService.class).to(CliDockerService.class);
    bind(CheckpointService.class).to(CliCheckpointService.class);
    bind(PersistenceService.class).to(DefaultPersistenceService.class);
    bind(ProcessStatusCallback.class).toInstance(instanceId -> {
    });
    bind(DefaultTaskVariablesService.class).toInstance(new MapBackedDefaultTaskVariablesService(readDefaultVars()));
    bind(LockService.class).to(CliLockService.class);
    bind(DependencyManager.class).toInstance(dependencyManager);
    bind(com.walmartlabs.concord.runtime.v2.sdk.DependencyManager.class).to(DefaultDependencyManager.class).in(Singleton.class);
    Multibinder.newSetBinder(binder(), ExecutionListener.class);
}
Also used : MapBackedDefaultTaskVariablesService(com.walmartlabs.concord.runtime.v2.runner.MapBackedDefaultTaskVariablesService) ProcessStatusCallback(com.walmartlabs.concord.runtime.v2.runner.ProcessStatusCallback) LockService(com.walmartlabs.concord.runtime.v2.sdk.LockService) DependencyManager(com.walmartlabs.concord.dependencymanager.DependencyManager) DefaultDependencyManager(com.walmartlabs.concord.runtime.v2.runner.DefaultDependencyManager) DockerService(com.walmartlabs.concord.runtime.v2.sdk.DockerService) BaseRunnerModule(com.walmartlabs.concord.runtime.v2.runner.guice.BaseRunnerModule) DefaultPersistenceService(com.walmartlabs.concord.runtime.v2.runner.DefaultPersistenceService) PersistenceService(com.walmartlabs.concord.runtime.v2.runner.PersistenceService) CheckpointService(com.walmartlabs.concord.runtime.v2.runner.checkpoints.CheckpointService) DefaultDependencyManager(com.walmartlabs.concord.runtime.v2.runner.DefaultDependencyManager) MapBackedDefaultTaskVariablesService(com.walmartlabs.concord.runtime.v2.runner.MapBackedDefaultTaskVariablesService) DefaultTaskVariablesService(com.walmartlabs.concord.runtime.v2.runner.DefaultTaskVariablesService) RunnerLogger(com.walmartlabs.concord.runtime.v2.runner.logging.RunnerLogger) SecretService(com.walmartlabs.concord.runtime.v2.sdk.SecretService)

Aggregations

DependencyManager (com.walmartlabs.concord.dependencymanager.DependencyManager)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Injector (com.google.inject.Injector)1 ImportManager (com.walmartlabs.concord.imports.ImportManager)1 ImportManagerFactory (com.walmartlabs.concord.imports.ImportManagerFactory)1 ImportProcessingException (com.walmartlabs.concord.imports.ImportProcessingException)1 RunnerConfiguration (com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration)1 ProjectLoaderV2 (com.walmartlabs.concord.runtime.v2.ProjectLoaderV2)1 ProjectSerializerV2 (com.walmartlabs.concord.runtime.v2.ProjectSerializerV2)1 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)1 Profile (com.walmartlabs.concord.runtime.v2.model.Profile)1 DefaultDependencyManager (com.walmartlabs.concord.runtime.v2.runner.DefaultDependencyManager)1 DefaultPersistenceService (com.walmartlabs.concord.runtime.v2.runner.DefaultPersistenceService)1 DefaultTaskVariablesService (com.walmartlabs.concord.runtime.v2.runner.DefaultTaskVariablesService)1 InjectorFactory (com.walmartlabs.concord.runtime.v2.runner.InjectorFactory)1 MapBackedDefaultTaskVariablesService (com.walmartlabs.concord.runtime.v2.runner.MapBackedDefaultTaskVariablesService)1 PersistenceService (com.walmartlabs.concord.runtime.v2.runner.PersistenceService)1 ProcessStatusCallback (com.walmartlabs.concord.runtime.v2.runner.ProcessStatusCallback)1 Runner (com.walmartlabs.concord.runtime.v2.runner.Runner)1 CheckpointService (com.walmartlabs.concord.runtime.v2.runner.checkpoints.CheckpointService)1