Search in sources :

Example 1 with PipelineNode

use of com.hp.octane.integrations.dto.pipelines.PipelineNode in project octane-gitlab-service by MicroFocus.

the class GitlabServices method createStructure.

PipelineNode createStructure(String buildId) {
    ParsedPath project = new ParsedPath(buildId, gitLabApi, PathType.MULTI_BRUNCH);
    // add a webhook to new Octane pipeline (gitlab project) in Octane
    try {
        if (project.isMultiBranch()) {
            addWebHookToProject(project.getFullPathOfProject(), true);
            return dtoFactory.newDTO(PipelineNode.class).setJobCiId(project.getJobCiId(true)).setMultiBranchType(MultiBranchType.MULTI_BRANCH_PARENT).setName(project.getNameWithNameSpaceForDisplayName()).setParameters(getParameters(project));
        }
        project = new ParsedPath(buildId, gitLabApi, PathType.PIPELINE);
        addWebHookToProject(project.getId(), true);
        return dtoFactory.newDTO(PipelineNode.class).setJobCiId(project.getJobCiId(false)).setName(project.getNameWithNameSpaceForDisplayName()).setParameters(getParameters(project));
    } catch (GitLabApiException e) {
        log.error("unable to update webhook when create a pipeline in Octane for project:" + project.getDisplayName(), e);
        return null;
    }
}
Also used : ParsedPath(com.microfocus.octane.gitlab.helpers.ParsedPath) GitLabApiException(org.gitlab4j.api.GitLabApiException) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode)

Example 2 with PipelineNode

use of com.hp.octane.integrations.dto.pipelines.PipelineNode in project octane-ci-java-sdk by MicroFocus.

the class TasksProcessorImpl method executePipelineRequest.

/**
 * this method is called by octane during adding new pipeline
 * @param result
 * @param jobId
 */
private void executePipelineRequest(OctaneResultAbridged result, String jobId) {
    PipelineNode content = configurer.pluginServices.getPipeline(jobId);
    if (content != null) {
        result.setBody(dtoFactory.dtoToJson(content));
        result.getHeaders().put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
        // update cache that new pipeline root is added
        configurationService.addToOctaneRootsCache(jobId);
    } else {
        result.setStatus(HttpStatus.SC_NOT_FOUND);
    }
}
Also used : PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode)

Example 3 with PipelineNode

use of com.hp.octane.integrations.dto.pipelines.PipelineNode in project octane-ci-java-sdk by MicroFocus.

the class TasksProcessorImpl method execute.

@Override
public OctaneResultAbridged execute(OctaneTaskAbridged task) {
    if (task == null) {
        throw new IllegalArgumentException("task MUST NOT be null");
    }
    if (task.getUrl() == null || task.getUrl().isEmpty()) {
        throw new IllegalArgumentException("task 'URL' MUST NOT be null nor empty");
    }
    if (!task.getUrl().contains(NGA_API)) {
        throw new IllegalArgumentException("task 'URL' expected to contain '" + NGA_API + "'; wrong handler call?");
    }
    long startTime = System.currentTimeMillis();
    logger.info(configurer.octaneConfiguration.getLocationForLog() + "processing task '" + task.getId() + "': " + task.getMethod() + " " + task.getUrl());
    OctaneResultAbridged result = DTOFactory.getInstance().newDTO(OctaneResultAbridged.class);
    result.setId(task.getId());
    result.setStatus(HttpStatus.SC_OK);
    result.setHeaders(new HashMap<>());
    result.setServiceId(configurer.octaneConfiguration.getInstanceId());
    String[] path = pathTokenizer(task.getUrl());
    try {
        if (path.length == 1 && STATUS.equals(path[0])) {
            executeStatusRequest(result);
        } else if (path.length == 1 && SUSPEND_STATUS.equals(path[0])) {
            suspendCiEvents(result, task.getBody());
        } else if (path[0].startsWith(JOBS)) {
            if (path.length == 1) {
                Map<String, String> queryParams = getQueryParamsMap(path[0]);
                boolean includingParameters = !"false".equals(queryParams.get("parameters"));
                Long workspaceId = queryParams.containsKey("workspaceId") ? Long.parseLong(queryParams.get("workspaceId")) : null;
                executeJobsListRequest(result, includingParameters, workspaceId);
            } else if (path.length == 2) {
                executePipelineRequest(result, path[1]);
            } else if (path.length == 3 && RUN.equals(path[2])) {
                executePipelineRunExecuteRequest(result, path[1], task.getBody());
            } else if (path.length == 3 && STOP.equals(path[2])) {
                executePipelineRunStopRequest(result, path[1], task.getBody());
            } else {
                result.setStatus(HttpStatus.SC_NOT_FOUND);
            }
        } else if (BUILD_STATUS.equalsIgnoreCase(path[0])) {
            executeGetBulkBuildStatusRequest(result, task.getBody());
        } else if (path.length == 2 && path[0].startsWith(BRANCHES)) {
            Map<String, String> queryParams = getQueryParamsMap(path[1]);
            String jobCiId = path[1].substring(0, path[1].indexOf("?"));
            String filterBranchName = queryParams.getOrDefault("filterBranchName", null);
            executeBranchesListRequest(result, jobCiId, filterBranchName);
        } else if (EXECUTOR.equalsIgnoreCase(path[0])) {
            if (HttpMethod.POST.equals(task.getMethod()) && path.length == 2) {
                if (INIT.equalsIgnoreCase(path[1])) {
                    DiscoveryInfo discoveryInfo = dtoFactory.dtoFromJson(task.getBody(), DiscoveryInfo.class);
                    discoveryInfo.setConfigurationId(configurer.octaneConfiguration.getInstanceId());
                    configurer.pluginServices.runTestDiscovery(discoveryInfo);
                    PipelineNode node = configurer.pluginServices.createExecutor(discoveryInfo);
                    if (node != null) {
                        result.setBody(dtoFactory.dtoToJson(node));
                        result.getHeaders().put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
                    }
                    result.setStatus(HttpStatus.SC_OK);
                } else if (TEST_CONN.equalsIgnoreCase(path[1])) {
                    TestConnectivityInfo testConnectivityInfo = dtoFactory.dtoFromJson(task.getBody(), TestConnectivityInfo.class);
                    OctaneResponse connTestResult = configurer.pluginServices.checkRepositoryConnectivity(testConnectivityInfo);
                    result.setStatus(connTestResult.getStatus());
                    result.setBody(connTestResult.getBody());
                } else if (CREDENTIALS_UPSERT.equalsIgnoreCase(path[1])) {
                    CredentialsInfo credentialsInfo = dtoFactory.dtoFromJson(task.getBody(), CredentialsInfo.class);
                    executeUpsertCredentials(result, credentialsInfo);
                } else {
                    result.setStatus(HttpStatus.SC_NOT_FOUND);
                }
            } else if (HttpMethod.DELETE.equals(task.getMethod()) && path.length == 2) {
                String id = path[1];
                configurer.pluginServices.deleteExecutor(id);
            } else if (HttpMethod.GET.equals(task.getMethod()) && path.length == 2) {
                if (CREDENTIALS.equalsIgnoreCase(path[1])) {
                    List<CredentialsInfo> credentials = configurer.pluginServices.getCredentials();
                    String json = dtoFactory.dtoCollectionToJson(credentials);
                    result.setBody(json);
                }
            }
        } else {
            result.setStatus(HttpStatus.SC_NOT_FOUND);
        }
    } catch (ErrorCodeBasedException pe) {
        logger.warn(configurer.octaneConfiguration.getLocationForLog() + "task execution failed; error: " + pe.getErrorCode() + ", message : " + pe.getMessage());
        result.setStatus(pe.getErrorCode());
        result.setBody(String.valueOf(pe.getErrorCode()));
    } catch (SPIMethodNotImplementedException spimnie) {
        result.setStatus(HttpStatus.SC_NOT_IMPLEMENTED);
    } catch (Throwable e) {
        logger.error(configurer.octaneConfiguration.getLocationForLog() + "task execution failed", e);
        result.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        TaskProcessingErrorBody errorBody = dtoFactory.newDTO(TaskProcessingErrorBody.class).setErrorMessage("Task " + task.getUrl() + " is failed. Server error message: " + e.getMessage());
        result.setBody(dtoFactory.dtoToJson(errorBody));
        result.getHeaders().put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
        logger.warn(configurer.octaneConfiguration.getLocationForLog() + "OctaneResultAbridged.execute failed : " + e.getMessage());
    }
    logger.info(configurer.octaneConfiguration.getLocationForLog() + "result for task '" + task.getId() + "' available with status " + result.getStatus() + ", processing time is " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds");
    return result;
}
Also used : TestConnectivityInfo(com.hp.octane.integrations.dto.executor.TestConnectivityInfo) CredentialsInfo(com.hp.octane.integrations.dto.executor.CredentialsInfo) SPIMethodNotImplementedException(com.hp.octane.integrations.exceptions.SPIMethodNotImplementedException) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode) DiscoveryInfo(com.hp.octane.integrations.dto.executor.DiscoveryInfo) ErrorCodeBasedException(com.hp.octane.integrations.exceptions.ErrorCodeBasedException)

Example 4 with PipelineNode

use of com.hp.octane.integrations.dto.pipelines.PipelineNode in project octane-ci-java-sdk by MicroFocus.

the class TaskingServiceTests method testJobsNoParamsAPI.

@Test
public void testJobsNoParamsAPI() {
    TasksProcessor tasksProcessor = client.getTasksProcessor();
    Assert.assertNotNull(tasksProcessor);
    OctaneTaskAbridged taskAbridged = dtoFactory.newDTO(OctaneTaskAbridged.class).setId(UUID.randomUUID().toString()).setUrl(OctaneSPEndpointSimulator.getSimulatorUrl() + APIPrefix + "/jobs?parameters=false");
    OctaneResultAbridged resultAbridged = tasksProcessor.execute(taskAbridged);
    runCommonAsserts(resultAbridged, taskAbridged.getId(), HttpStatus.SC_OK);
    CIJobsList ciJobsList = dtoFactory.dtoFromJson(resultAbridged.getBody(), CIJobsList.class);
    Assert.assertNotNull(ciJobsList);
    Assert.assertNotNull(ciJobsList.getJobs());
    Assert.assertEquals(3, ciJobsList.getJobs().length);
    for (PipelineNode ciJob : ciJobsList.getJobs()) {
        Assert.assertNotNull(ciJob);
        Assert.assertTrue(ciJob.getName().startsWith("Job "));
        Assert.assertTrue(ciJob.getJobCiId().startsWith("job-"));
        Assert.assertNotNull(ciJob.getParameters());
        Assert.assertTrue(ciJob.getParameters().isEmpty());
    }
}
Also used : CIJobsList(com.hp.octane.integrations.dto.general.CIJobsList) OctaneResultAbridged(com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode) OctaneTaskAbridged(com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged) Test(org.junit.Test)

Example 5 with PipelineNode

use of com.hp.octane.integrations.dto.pipelines.PipelineNode in project octane-ci-java-sdk by MicroFocus.

the class TaskingServiceTests method testJobsWithParamsAPI.

@Test
public void testJobsWithParamsAPI() {
    TasksProcessor tasksProcessor = client.getTasksProcessor();
    Assert.assertNotNull(tasksProcessor);
    OctaneTaskAbridged taskAbridged = dtoFactory.newDTO(OctaneTaskAbridged.class).setId(UUID.randomUUID().toString()).setUrl(OctaneSPEndpointSimulator.getSimulatorUrl() + APIPrefix + "/jobs");
    OctaneResultAbridged resultAbridged = tasksProcessor.execute(taskAbridged);
    runCommonAsserts(resultAbridged, taskAbridged.getId(), HttpStatus.SC_OK);
    CIJobsList ciJobsList = dtoFactory.dtoFromJson(resultAbridged.getBody(), CIJobsList.class);
    Assert.assertNotNull(ciJobsList);
    Assert.assertNotNull(ciJobsList.getJobs());
    Assert.assertEquals(3, ciJobsList.getJobs().length);
    for (PipelineNode ciJob : ciJobsList.getJobs()) {
        Assert.assertNotNull(ciJob);
        Assert.assertTrue(ciJob.getName().startsWith("Job "));
        Assert.assertTrue(ciJob.getJobCiId().startsWith("job-"));
        Assert.assertNotNull(ciJob.getParameters());
        Assert.assertEquals(3, ciJob.getParameters().size());
        for (CIParameter ciParameter : ciJob.getParameters()) {
            Assert.assertNotNull(ciParameter);
            Assert.assertNotNull(ciParameter.getName());
            Assert.assertNotNull(ciParameter.getType());
            Assert.assertNotNull(ciParameter.getValue());
        }
    }
}
Also used : CIJobsList(com.hp.octane.integrations.dto.general.CIJobsList) OctaneResultAbridged(com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode) OctaneTaskAbridged(com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged) CIParameter(com.hp.octane.integrations.dto.parameters.CIParameter) Test(org.junit.Test)

Aggregations

PipelineNode (com.hp.octane.integrations.dto.pipelines.PipelineNode)8 OctaneResultAbridged (com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged)3 OctaneTaskAbridged (com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged)3 CIJobsList (com.hp.octane.integrations.dto.general.CIJobsList)3 Test (org.junit.Test)3 CIParameter (com.hp.octane.integrations.dto.parameters.CIParameter)2 ParsedPath (com.microfocus.octane.gitlab.helpers.ParsedPath)2 ArrayList (java.util.ArrayList)2 GitLabApiException (org.gitlab4j.api.GitLabApiException)2 CredentialsInfo (com.hp.octane.integrations.dto.executor.CredentialsInfo)1 DiscoveryInfo (com.hp.octane.integrations.dto.executor.DiscoveryInfo)1 TestConnectivityInfo (com.hp.octane.integrations.dto.executor.TestConnectivityInfo)1 ErrorCodeBasedException (com.hp.octane.integrations.exceptions.ErrorCodeBasedException)1 SPIMethodNotImplementedException (com.hp.octane.integrations.exceptions.SPIMethodNotImplementedException)1 MalformedURLException (java.net.MalformedURLException)1 Project (org.gitlab4j.api.models.Project)1 ProjectFilter (org.gitlab4j.api.models.ProjectFilter)1