Search in sources :

Example 1 with Provider

use of org.guvnor.ala.runtime.providers.Provider 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 2 with Provider

use of org.guvnor.ala.runtime.providers.Provider in project kie-wb-common by kiegroup.

the class RestPipelineImplTest method testAPI.

@Test
public void testAPI() {
    ProviderTypeList allProviderTypes = runtimeService.getProviderTypes(0, 10, "", true);
    assertEquals(2, allProviderTypes.getItems().size());
    DockerProviderConfig dockerProviderConfig = new DockerProviderConfig() {
    };
    runtimeService.registerProvider(dockerProviderConfig);
    ProviderList allProviders = runtimeService.getProviders(0, 10, "", true);
    assertEquals(1, allProviders.getItems().size());
    Provider p = allProviders.getItems().get(0);
    assertTrue(p instanceof DockerProvider);
    // by construction.
    int systemPipelines = 2;
    PipelineConfigsList allPipelineConfigs = pipelineService.getPipelineConfigs(0, 10, "", true);
    assertNotNull(allPipelineConfigs);
    assertEquals(systemPipelines, allPipelineConfigs.getItems().size());
    List<PipelineConfigStage> configs = new ArrayList<>();
    configs.add(new PipelineConfigStage("GitConfig", new GitConfigImpl()));
    configs.add(new PipelineConfigStage("MavenProjectConfig", new MavenProjectConfigImpl()));
    configs.add(new PipelineConfigStage("MavenBuildConfig", new MavenBuildConfigImpl()));
    configs.add(new PipelineConfigStage("DockerBuildConfig", new DockerBuildConfigImpl()));
    configs.add(new PipelineConfigStage("MavenBuildExecConfigImpl", new MavenBuildExecConfigImpl()));
    configs.add(new PipelineConfigStage("DockerProviderConfig", new DockerProviderConfigImpl()));
    configs.add(new PipelineConfigStage("ContextAwareDockerProvisioningConfig", new ContextAwareDockerProvisioningConfig()));
    configs.add(new PipelineConfigStage("ContextAwareDockerRuntimeExecConfig", new ContextAwareDockerRuntimeExecConfig()));
    pipelineService.newPipeline(new PipelineConfigImpl("mypipe", configs));
    pipelineService.newPipeline(new PipelineConfigImpl("wildlfyPipe", configs), WildflyProviderType.instance());
    pipelineService.newPipeline(new PipelineConfigImpl("dockerPipe", configs), DockerProviderType.instance());
    allPipelineConfigs = pipelineService.getPipelineConfigs(0, 10, "", true);
    int createdPipelines = 3;
    int totalPipelines = systemPipelines + createdPipelines;
    assertEquals(totalPipelines, allPipelineConfigs.getItems().size());
    PipelineConfigsList wildflyConfigs = pipelineService.getPipelineConfigs(WildflyProviderType.instance().getProviderTypeName(), WildflyProviderType.instance().getVersion(), 0, 10, "", true);
    assertEquals(2, wildflyConfigs.getItems().size());
    List<String> wildflyPipelineNames = pipelineService.getPipelineNames(WildflyProviderType.instance().getProviderTypeName(), WildflyProviderType.instance().getVersion(), 0, 10, "", true);
    assertEquals(2, wildflyPipelineNames.size());
    assertTrue(wildflyPipelineNames.contains("wildlfyPipe"));
    assertTrue(wildflyPipelineNames.contains(SYSTEM_PIPELINE1));
    PipelineConfigsList dockerConfigs = pipelineService.getPipelineConfigs(DockerProviderType.instance().getProviderTypeName(), DockerProviderType.instance().getVersion(), 0, 10, "", true);
    assertEquals(1, dockerConfigs.getItems().size());
    List<String> dockerPipelineNames = pipelineService.getPipelineNames(DockerProviderType.instance().getProviderTypeName(), DockerProviderType.instance().getVersion(), 0, 10, "", true);
    assertEquals(1, dockerPipelineNames.size());
    assertTrue(dockerPipelineNames.contains("dockerPipe"));
    Input input = new Input();
    input.put("provider-name", "local");
    input.put("repo-name", "drools-workshop");
    input.put("create-repo", "true");
    input.put("branch", "master");
    input.put("out-dir", tempPath.getAbsolutePath());
    input.put("origin", gitUrl);
    String pipelineExecutionId = pipelineService.runPipeline("mypipe", input, false);
    RuntimeQueryResultItemList itemList = runtimeService.executeQuery(RuntimeQueryBuilder.newInstance().withPipelineExecutionId(pipelineExecutionId).build());
    assertEquals(1, itemList.getItems().size());
    assertEquals(pipelineExecutionId, itemList.getItems().get(0).getPipelineExecutionId());
    pipelineService.deletePipelineExecution(pipelineExecutionId);
    itemList = runtimeService.executeQuery(RuntimeQueryBuilder.newInstance().withPipelineExecutionId(pipelineExecutionId).build());
    assertEquals(1, itemList.getItems().size());
    assertNull(itemList.getItems().get(0).getPipelineExecutionId());
    RuntimeList allRuntimes = runtimeService.getRuntimes(0, 10, "", true);
    assertEquals(1, allRuntimes.getItems().size());
    runtimeService.destroyRuntime(allRuntimes.getItems().get(0).getId(), true);
    allRuntimes = runtimeService.getRuntimes(0, 10, "", true);
    assertEquals(0, allRuntimes.getItems().size());
    assertEquals(18, // 8 Stages x 2 + 2 pipeline events
    listener.getEvents().size());
    pipelineExecutionId = pipelineService.runPipeline("mypipe", input, true);
    pipelineService.stopPipelineExecution(pipelineExecutionId);
    itemList = runtimeService.executeQuery(RuntimeQueryBuilder.newInstance().withPipelineExecutionId(pipelineExecutionId).build());
    assertEquals(1, itemList.getItems().size());
    assertEquals(pipelineExecutionId, itemList.getItems().get(0).getPipelineExecutionId());
    assertEquals(PipelineExecutorTask.Status.STOPPED.name(), itemList.getItems().get(0).getPipelineStatus());
}
Also used : RuntimeQueryResultItemList(org.guvnor.ala.services.api.itemlist.RuntimeQueryResultItemList) ProviderList(org.guvnor.ala.services.api.itemlist.ProviderList) MavenProjectConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenProjectConfigImpl) ContextAwareDockerProvisioningConfig(org.guvnor.ala.docker.config.impl.ContextAwareDockerProvisioningConfig) DockerBuildConfigImpl(org.guvnor.ala.docker.config.impl.DockerBuildConfigImpl) DockerProvider(org.guvnor.ala.docker.model.DockerProvider) GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) ArrayList(java.util.ArrayList) DockerProviderConfigImpl(org.guvnor.ala.docker.config.impl.DockerProviderConfigImpl) DockerProviderConfig(org.guvnor.ala.docker.config.DockerProviderConfig) ProviderTypeList(org.guvnor.ala.services.api.itemlist.ProviderTypeList) DockerProvider(org.guvnor.ala.docker.model.DockerProvider) Provider(org.guvnor.ala.runtime.providers.Provider) Input(org.guvnor.ala.pipeline.Input) PipelineConfigStage(org.guvnor.ala.pipeline.PipelineConfigStage) MavenBuildExecConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenBuildExecConfigImpl) RuntimeList(org.guvnor.ala.services.api.itemlist.RuntimeList) PipelineConfigsList(org.guvnor.ala.services.api.itemlist.PipelineConfigsList) MavenBuildConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenBuildConfigImpl) PipelineConfigImpl(org.guvnor.ala.pipeline.impl.PipelineConfigImpl) ContextAwareDockerRuntimeExecConfig(org.guvnor.ala.docker.config.impl.ContextAwareDockerRuntimeExecConfig) Test(org.junit.Test)

Example 3 with Provider

use of org.guvnor.ala.runtime.providers.Provider in project kie-wb-common by kiegroup.

the class RestRuntimeProvisioningImplTest method testAPI.

@Test
public void testAPI() {
    ProviderTypeList allProviderTypes = runtimeService.getProviderTypes(0, 10, "", true);
    assertEquals(2, allProviderTypes.getItems().size());
    DockerProviderConfig dockerProviderConfig = new DockerProviderConfig() {
    };
    runtimeService.registerProvider(dockerProviderConfig);
    ProviderList allProviders = runtimeService.getProviders(0, 10, "", true);
    assertEquals(1, allProviders.getItems().size());
    Provider p = allProviders.getItems().get(0);
    assertTrue(p instanceof DockerProvider);
    assertNotNull(p.getId());
    assertNotNull(p.getProviderType());
    assertNotNull(p.getConfig());
    DockerRuntimeConfig dockerRuntimeConfiguration = new DockerRuntimeConfig() {

        @Override
        public String getImage() {
            return "kitematic/hello-world-nginx";
        }

        @Override
        public String getPort() {
            return "8080";
        }

        @Override
        public boolean isPull() {
            return true;
        }

        @Override
        public ProviderId getProviderId() {
            return p;
        }
    };
    String newRuntime = runtimeService.newRuntime(dockerRuntimeConfiguration);
    assertNotNull(newRuntime);
    RuntimeList allRuntimes = runtimeService.getRuntimes(0, 10, "", true);
    assertEquals(1, allRuntimes.getItems().size());
    RuntimeQuery query = RuntimeQueryBuilder.newInstance().withProviderId(p.getId()).build();
    RuntimeQueryResultItemList queryResult = runtimeService.executeQuery(query);
    assertEquals(1, queryResult.getItems().size());
    assertEquals(RuntimeState.RUNNING, queryResult.getItems().get(0).getRuntimeStatus());
    runtimeService.destroyRuntime(newRuntime, true);
    allRuntimes = runtimeService.getRuntimes(0, 10, "", true);
    assertEquals(0, allRuntimes.getItems().size());
}
Also used : RuntimeQueryResultItemList(org.guvnor.ala.services.api.itemlist.RuntimeQueryResultItemList) ProviderList(org.guvnor.ala.services.api.itemlist.ProviderList) DockerProvider(org.guvnor.ala.docker.model.DockerProvider) RuntimeList(org.guvnor.ala.services.api.itemlist.RuntimeList) RuntimeQuery(org.guvnor.ala.services.api.RuntimeQuery) DockerRuntimeConfig(org.guvnor.ala.docker.config.DockerRuntimeConfig) DockerProviderConfig(org.guvnor.ala.docker.config.DockerProviderConfig) ProviderTypeList(org.guvnor.ala.services.api.itemlist.ProviderTypeList) DockerProvider(org.guvnor.ala.docker.model.DockerProvider) Provider(org.guvnor.ala.runtime.providers.Provider) Test(org.junit.Test)

Example 4 with Provider

use of org.guvnor.ala.runtime.providers.Provider in project kie-wb-common by kiegroup.

the class InMemoryRuntimeRegistryTest method testGetProviders.

@Test
public void testGetProviders() {
    List<Provider> result = runtimeRegistry.getProviders(0, 1000, RuntimeRegistry.PROVIDER_ID_SORT, true);
    assertTrue(result.isEmpty());
    List<Provider> providers = mockProviderListSPI(providerType, ELEMENTS_COUNT);
    providers.forEach(provider -> runtimeRegistry.registerProvider(provider));
    result = runtimeRegistry.getProviders(0, 1000, RuntimeRegistry.PROVIDER_ID_SORT, true);
    for (Provider provider : providers) {
        assertTrue(result.contains(provider));
    }
}
Also used : Provider(org.guvnor.ala.runtime.providers.Provider) Test(org.junit.Test)

Example 5 with Provider

use of org.guvnor.ala.runtime.providers.Provider in project kie-wb-common by kiegroup.

the class OpenShiftProviderConfigExecutor method apply.

@Override
public Optional<OpenShiftProvider> apply(final OpenShiftProviderConfig openshiftProviderConfig) {
    if (openshiftProviderConfig.getName() == null || openshiftProviderConfig.getName().isEmpty()) {
        throw new ProvisioningException("No name was provided for the OpenShiftProviderConfig.getName() " + "configuration parameter. You might probably have to properly set " + "the pipeline input parameter: " + ProviderConfig.PROVIDER_NAME);
    }
    Provider provider = runtimeRegistry.getProvider(openshiftProviderConfig.getName());
    OpenShiftProvider openshiftProvider;
    if (provider != null) {
        if (!(provider instanceof OpenShiftProvider)) {
            throw new ProvisioningException("The provider: " + openshiftProviderConfig.getName() + " must be an instance of " + OpenShiftProviderConfig.class + " but is: " + provider.getClass());
        } else {
            openshiftProvider = (OpenShiftProvider) provider;
        }
    } else {
        openshiftProvider = new OpenShiftProviderImpl(openshiftProviderConfig.getName(), openshiftProviderConfig);
        runtimeRegistry.registerProvider(openshiftProvider);
    }
    return Optional.of(openshiftProvider);
}
Also used : ProvisioningException(org.guvnor.ala.exceptions.ProvisioningException) OpenShiftProvider(org.guvnor.ala.openshift.model.OpenShiftProvider) OpenShiftProviderConfig(org.guvnor.ala.openshift.config.OpenShiftProviderConfig) Provider(org.guvnor.ala.runtime.providers.Provider) OpenShiftProvider(org.guvnor.ala.openshift.model.OpenShiftProvider) OpenShiftProviderImpl(org.guvnor.ala.openshift.model.OpenShiftProviderImpl)

Aggregations

Provider (org.guvnor.ala.runtime.providers.Provider)10 Test (org.junit.Test)6 ProviderType (org.guvnor.ala.runtime.providers.ProviderType)3 ProviderList (org.guvnor.ala.services.api.itemlist.ProviderList)3 ArrayList (java.util.ArrayList)2 DockerProviderConfig (org.guvnor.ala.docker.config.DockerProviderConfig)2 DockerProvider (org.guvnor.ala.docker.model.DockerProvider)2 ProvisioningException (org.guvnor.ala.exceptions.ProvisioningException)2 ProviderTypeList (org.guvnor.ala.services.api.itemlist.ProviderTypeList)2 RuntimeList (org.guvnor.ala.services.api.itemlist.RuntimeList)2 RuntimeQueryResultItemList (org.guvnor.ala.services.api.itemlist.RuntimeQueryResultItemList)2 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Collectors (java.util.stream.Collectors)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 MavenBuildConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenBuildConfigImpl)1 MavenBuildExecConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenBuildExecConfigImpl)1