Search in sources :

Example 1 with Pipeline

use of org.guvnor.ala.pipeline.Pipeline in project kie-wb-common by kiegroup.

the class MavenDependencyConfigExecutorTest method testMavenDependencyAPI.

@Test
public void testMavenDependencyAPI() throws Exception {
    final String groupId = "org.guvnor.ala";
    final String artifactId = "maven-ala-artifact-test";
    final String version = "1";
    final String artifactPath = "/org/guvnor/ala/maven-ala-artifact-test/1/maven-ala-artifact-test-1.pom";
    final String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
    try {
        final Path settingsXmlPath = generateSettingsXml();
        System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
        MavenSettings.reinitSettings();
        installArtifactLocally(groupId, artifactId, version);
        final BuildRegistry buildRegistry = new InMemoryBuildRegistry();
        final Pipeline pipe = PipelineFactory.newBuilder().addConfigStage("Maven Artifact", new MavenDependencyConfigImpl()).buildAs("my pipe");
        final PipelineExecutor executor = new PipelineExecutor(singletonList(new MavenDependencyConfigExecutor(buildRegistry)));
        executor.execute(new Input() {

            {
                put("artifact", groupId + ":" + artifactId + ":pom:" + version);
            }
        }, pipe, System.out::println);
        final List<Binary> allBinaries = buildRegistry.getAllBinaries();
        assertNotNull(allBinaries);
        assertEquals(1, allBinaries.size());
        assertTrue(allBinaries.get(0) instanceof MavenBinary);
        final MavenBinary binary = (MavenBinary) allBinaries.get(0);
        assertEquals("Maven", binary.getType());
        assertEquals(artifactId, binary.getName());
        assertEquals(groupId, binary.getGroupId());
        assertEquals(artifactId, binary.getArtifactId());
        assertEquals(version, binary.getVersion());
        assertEquals(Paths.get(m2Folder.getPath(), artifactPath).toString(), binary.getPath().toString());
    } finally {
        if (oldSettingsXmlPath == null) {
            System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
        } else {
            System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
        }
        MavenSettings.reinitSettings();
    }
}
Also used : Path(java.nio.file.Path) InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) MavenDependencyConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenDependencyConfigImpl) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) PipelineExecutor(org.guvnor.ala.pipeline.execution.PipelineExecutor) Pipeline(org.guvnor.ala.pipeline.Pipeline) Input(org.guvnor.ala.pipeline.Input) BuildRegistry(org.guvnor.ala.registry.BuildRegistry) InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) Binary(org.guvnor.ala.build.Binary) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) Test(org.junit.Test)

Example 2 with Pipeline

use of org.guvnor.ala.pipeline.Pipeline in project kie-wb-common by kiegroup.

the class MavenProjectConfigExecutorTest method testAPI.

@Test
public void testAPI() {
    final SourceRegistry sourceRegistry = new InMemorySourceRegistry();
    final BuildRegistry buildRegistry = new InMemoryBuildRegistry();
    final Pipeline pipe = PipelineFactory.newBuilder().addConfigStage("Git Source", new MyGitConfig()).addConfigStage("Maven Project", new MavenProjectConfigImpl()).addConfigStage("Maven Build Config", new MavenBuildConfigImpl()).addConfigStage("Maven Build", new MavenBuildExecConfigImpl()).buildAs("my pipe");
    final PipelineExecutor executor = new PipelineExecutor(asList(new GitConfigExecutor(sourceRegistry), new MavenProjectConfigExecutor(sourceRegistry), new MavenBuildConfigExecutor(), new MavenBuildExecConfigExecutor(buildRegistry)));
    executor.execute(new Input() {

        {
            put("repo-name", "drools-workshop-pipe");
            put("create-repo", "true");
            put("branch", "master");
            put("out-dir", tempPath.getAbsolutePath());
            put("origin", gitUrl);
        }
    }, pipe, System.out::println);
    List<Repository> allRepositories = sourceRegistry.getAllRepositories();
    assertEquals(1, allRepositories.size());
    Repository repo = allRepositories.get(0);
    List<Project> allProjects = sourceRegistry.getAllProjects(repo);
    assertEquals(1, allProjects.size());
    List<Binary> allBinaries = buildRegistry.getAllBinaries();
    assertEquals(1, allBinaries.size());
    assertMavenBinary(allBinaries.get(0), allProjects.get(0));
    final String tempDir = sourceRegistry.getAllProjects(repo).get(0).getTempDir();
    executor.execute(new Input() {

        {
            put("project-temp-dir", tempDir);
            put("repo-name", "drools-workshop-pipe");
            put("branch", "master");
        }
    }, pipe, System.out::println);
    allRepositories = sourceRegistry.getAllRepositories();
    assertEquals(1, allRepositories.size());
    repo = allRepositories.get(0);
    allProjects = sourceRegistry.getAllProjects(repo);
    assertEquals(2, allProjects.size());
    allBinaries = buildRegistry.getAllBinaries();
    assertEquals(1, allBinaries.size());
    assertMavenBinary(allBinaries.get(0), allProjects.get(1));
}
Also used : InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) MavenProjectConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenProjectConfigImpl) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) SourceRegistry(org.guvnor.ala.registry.SourceRegistry) PipelineExecutor(org.guvnor.ala.pipeline.execution.PipelineExecutor) Pipeline(org.guvnor.ala.pipeline.Pipeline) Project(org.guvnor.ala.build.Project) MavenProject(org.apache.maven.project.MavenProject) GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) Input(org.guvnor.ala.pipeline.Input) Repository(org.guvnor.ala.source.Repository) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) MavenBuildExecConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenBuildExecConfigImpl) BuildRegistry(org.guvnor.ala.registry.BuildRegistry) InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) MavenBuildConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenBuildConfigImpl) Binary(org.guvnor.ala.build.Binary) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) Test(org.junit.Test)

Example 3 with Pipeline

use of org.guvnor.ala.pipeline.Pipeline in project kie-wb-common by kiegroup.

the class ProvisioningPipelinesProducer method getWildflyPipeline.

/**
 * Produces a pipeline for provisioning building an provisioning war applications into an Wildlfy server.
 */
@Produces
public SystemPipelineDescriptor getWildflyPipeline() {
    return new SystemPipelineDescriptor() {

        @Override
        public Optional<ProviderType> getProviderType() {
            return Optional.of(WildflyProviderType.instance());
        }

        @Override
        public Pipeline getPipeline() {
            // Create Wildfly Pipeline Configuration
            final GitConfig gitConfig = new GitConfig() {
            };
            final MavenProjectConfig projectConfig = new MavenProjectConfig() {
            };
            final MavenBuildConfig mavenBuildConfig = new MavenBuildConfig() {

                @Override
                public List<String> getGoals() {
                    final List<String> result = new ArrayList<>();
                    result.add("clean");
                    result.add("package");
                    return result;
                }

                @Override
                public Properties getProperties() {
                    final Properties result = new Properties();
                    result.setProperty("failIfNoTests", "false");
                    return result;
                }
            };
            final MavenBuildExecConfig mavenBuildExecConfig = new MavenBuildExecConfig() {
            };
            final WildflyProviderConfig wildflyProviderConfig = new WildflyProviderConfig() {
            };
            final ContextAwareWildflyRuntimeExecConfig wildflyRuntimeExecConfig = new ContextAwareWildflyRuntimeExecConfig() {
            };
            final Pipeline pipeline = PipelineFactory.newBuilder().addConfigStage("Git Source", gitConfig).addConfigStage("Maven Project", projectConfig).addConfigStage("Maven Build Config", mavenBuildConfig).addConfigStage("Maven Build", mavenBuildExecConfig).addConfigStage("Wildfly Provider Config", wildflyProviderConfig).addConfigStage("Wildfly Runtime Exec", wildflyRuntimeExecConfig).buildAs("source-to-wildlfy-provisioning");
            return pipeline;
        }
    };
}
Also used : WildflyProviderConfig(org.guvnor.ala.wildfly.config.WildflyProviderConfig) ArrayList(java.util.ArrayList) MavenBuildConfig(org.guvnor.ala.build.maven.config.MavenBuildConfig) Properties(java.util.Properties) Pipeline(org.guvnor.ala.pipeline.Pipeline) MavenBuildExecConfig(org.guvnor.ala.build.maven.config.MavenBuildExecConfig) SystemPipelineDescriptor(org.guvnor.ala.pipeline.SystemPipelineDescriptor) MavenProjectConfig(org.guvnor.ala.build.maven.config.MavenProjectConfig) ContextAwareWildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.impl.ContextAwareWildflyRuntimeExecConfig) GitConfig(org.guvnor.ala.source.git.config.GitConfig) ProviderType(org.guvnor.ala.runtime.providers.ProviderType) WildflyProviderType(org.guvnor.ala.wildfly.model.WildflyProviderType) Produces(javax.enterprise.inject.Produces)

Example 4 with Pipeline

use of org.guvnor.ala.pipeline.Pipeline in project kie-wb-common by kiegroup.

the class RestPipelineServiceImpl method runPipeline.

@Override
public String runPipeline(final String pipelineId, final Input input, final boolean async) throws BusinessException {
    final Pipeline pipeline = pipelineRegistry.getPipelineByName(pipelineId);
    if (pipeline == null) {
        throw new BusinessException("Pipeline: " + pipelineId + " was not found.");
    }
    String providerName = input.get(ProviderConfig.PROVIDER_NAME);
    Provider provider = null;
    ProviderType providerType = null;
    PipelineExecutorTaskDef taskDef;
    if (providerName != null && !providerName.isEmpty()) {
        provider = runtimeRegistry.getProvider(providerName);
    }
    if (provider == null) {
        providerType = pipelineRegistry.getProviderType(pipelineId);
    }
    if (provider != null) {
        taskDef = new PipelineExecutorTaskDefImpl(pipeline, input, provider);
    } else if (providerType != null) {
        taskDef = new PipelineExecutorTaskDefImpl(pipeline, input, providerType);
    } else {
        taskDef = new PipelineExecutorTaskDefImpl(pipeline, input);
    }
    return executorTaskManager.execute(taskDef, async ? PipelineExecutorTaskManager.ExecutionMode.ASYNCHRONOUS : PipelineExecutorTaskManager.ExecutionMode.SYNCHRONOUS);
}
Also used : PipelineExecutorTaskDefImpl(org.guvnor.ala.pipeline.execution.impl.PipelineExecutorTaskDefImpl) BusinessException(org.guvnor.ala.services.exceptions.BusinessException) ProviderType(org.guvnor.ala.runtime.providers.ProviderType) ConfigBasedPipeline(org.guvnor.ala.pipeline.ConfigBasedPipeline) Pipeline(org.guvnor.ala.pipeline.Pipeline) Provider(org.guvnor.ala.runtime.providers.Provider) PipelineExecutorTaskDef(org.guvnor.ala.pipeline.execution.PipelineExecutorTaskDef)

Example 5 with Pipeline

use of org.guvnor.ala.pipeline.Pipeline in project kie-wb-common by kiegroup.

the class PipelineExecutorTaskManagerImpl method startAsyncTask.

/**
 * Executes a task in asynchronous mode.
 * @param task the task for execute.
 * @return the taskId of the task.
 */
private synchronized void startAsyncTask(final PipelineExecutorTask task) {
    final Future<?> future = executor.submit(() -> {
        final Pipeline pipeline = pipelineRegistry.getPipelineByName(task.getTaskDef().getPipeline());
        try {
            pipelineExecutor.execute(task.getTaskDef().getInput(), pipeline, output -> processPipelineOutput(task, output), localListener);
        } catch (Exception e) {
            logger.error("An error was produced during pipeline execution for PipelineExecutorTask: " + task.getId(), e);
        } finally {
            removeTaskEntry(task.getId());
            removeFutureTask(task.getId());
        }
    });
    storeFutureTask(task.getId(), future);
}
Also used : PipelineExecutorException(org.guvnor.ala.pipeline.execution.PipelineExecutorException) Pipeline(org.guvnor.ala.pipeline.Pipeline)

Aggregations

Pipeline (org.guvnor.ala.pipeline.Pipeline)27 Test (org.junit.Test)15 Input (org.guvnor.ala.pipeline.Input)12 PipelineExecutor (org.guvnor.ala.pipeline.execution.PipelineExecutor)8 ArrayList (java.util.ArrayList)6 BuildRegistry (org.guvnor.ala.registry.BuildRegistry)6 InMemoryBuildRegistry (org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry)6 InMemoryRuntimeRegistry (org.guvnor.ala.registry.inmemory.InMemoryRuntimeRegistry)5 Runtime (org.guvnor.ala.runtime.Runtime)5 Stage (org.guvnor.ala.pipeline.Stage)4 SourceRegistry (org.guvnor.ala.registry.SourceRegistry)4 InMemorySourceRegistry (org.guvnor.ala.registry.inmemory.InMemorySourceRegistry)4 GitConfigExecutor (org.guvnor.ala.source.git.executor.GitConfigExecutor)4 MavenBuildConfig (org.guvnor.ala.build.maven.config.MavenBuildConfig)3 MavenBuildExecConfig (org.guvnor.ala.build.maven.config.MavenBuildExecConfig)3 MavenProjectConfig (org.guvnor.ala.build.maven.config.MavenProjectConfig)3 MavenBuildConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenBuildConfigImpl)3 MavenBuildExecConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenBuildExecConfigImpl)3 MavenProjectConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenProjectConfigImpl)3 MavenBuildConfigExecutor (org.guvnor.ala.build.maven.executor.MavenBuildConfigExecutor)3