Search in sources :

Example 1 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.

the class PipelineFileGenerationManager method fillTemplateForPipelineVersion.

public byte[] fillTemplateForPipelineVersion(Long pipelineId, String pipelineVersion, String templatePath, GenerateFileVO generateFileVO) {
    try {
        PipelineDocumentTemplate documentTemplate = pipelineDocumentTemplateManager.loadPipelineDocumentTemplateWithSpecificVersion(pipelineId, pipelineVersion);
        documentTemplate.applyLuigiWorkflowGraph(generateFileVO.getLuigiWorkflowGraphVO());
        return this.generateFile(templatePath, documentTemplate);
    } catch (GitClientException e) {
        return null;
    }
}
Also used : GitClientException(com.epam.pipeline.exception.git.GitClientException) PipelineDocumentTemplate(com.epam.pipeline.manager.pipeline.documents.templates.PipelineDocumentTemplate)

Example 2 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.

the class PipelineFileGenerationManager method generateFile.

private byte[] generateFile(String templatePath, PipelineDocumentTemplate documentTemplate) {
    try {
        byte[] docxTemplateData = gitManager.getPipelineFileContents(documentTemplate.getPipeline(), documentTemplate.getVersion().getName(), templatePath);
        ByteArrayInputStream inputStream = new ByteArrayInputStream(docxTemplateData);
        XWPFDocument document = new XWPFDocument(inputStream);
        documentTemplate.fillTemplate(document);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        document.write(outputStream);
        return outputStream.toByteArray();
    } catch (GitClientException | IOException e) {
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) GitClientException(com.epam.pipeline.exception.git.GitClientException) XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.

the class PipelineDocumentTemplateManager method loadPipelineDocumentTemplateWithSpecificVersion.

public PipelineDocumentTemplate loadPipelineDocumentTemplateWithSpecificVersion(Long pipelineId, String version) throws GitClientException {
    Pipeline pipeline = pipelineManager.load(pipelineId);
    List<Revision> revisions = pipelineVersionManager.loadAllVersionFromGit(pipelineId, null);
    Optional<Revision> oRevision = revisions.stream().filter(r -> r.getName().equals(version)).findAny();
    PipelineDocumentTemplate template = oRevision.map(revision -> new PipelineDocumentTemplate(pipeline, revision)).orElseGet(() -> new PipelineDocumentTemplate(pipeline));
    this.fillTemplate(template);
    return template;
}
Also used : PipelineManager(com.epam.pipeline.manager.pipeline.PipelineManager) GitClientException(com.epam.pipeline.exception.git.GitClientException) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) DocumentGenerationPropertyManager(com.epam.pipeline.manager.pipeline.DocumentGenerationPropertyManager) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) PipelineVersionManager(com.epam.pipeline.manager.pipeline.PipelineVersionManager) ArrayList(java.util.ArrayList) Service(org.springframework.stereotype.Service) TaskNode(com.epam.pipeline.entity.graph.TaskNode) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) GitManager(com.epam.pipeline.manager.git.GitManager) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Tool(com.epam.pipeline.entity.pipeline.Tool) DataStorageRuleManager(com.epam.pipeline.manager.datastorage.DataStorageRuleManager) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TaskGraphVO(com.epam.pipeline.controller.vo.TaskGraphVO) Revision(com.epam.pipeline.entity.pipeline.Revision) Optional(java.util.Optional) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) DataStorageRule(com.epam.pipeline.entity.datastorage.rules.DataStorageRule) Revision(com.epam.pipeline.entity.pipeline.Revision) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 4 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.

the class PipelineVersionManager method getWorkflowGraph.

public TaskGraphVO getWorkflowGraph(Long id, String version) {
    Pipeline pipeline = pipelineManager.load(id);
    try {
        gitManager.loadRevision(pipeline, version);
    } catch (GitClientException e) {
        LOGGER.error(e.getMessage(), e);
        throw new IllegalArgumentException(e.getMessage());
    }
    File config = gitManager.getConfigFile(pipeline, version);
    TaskGraphVO result = new GraphReader().readGraph(graphScript, config.getParentFile().getAbsolutePath(), CONFIG_FILE_NAME);
    mergeToolsRequirements(result);
    try {
        FileUtils.deleteDirectory(config.getParentFile());
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return result;
}
Also used : GraphReader(com.epam.pipeline.manager.python.GraphReader) GitClientException(com.epam.pipeline.exception.git.GitClientException) TaskGraphVO(com.epam.pipeline.controller.vo.TaskGraphVO) IOException(java.io.IOException) File(java.io.File) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 5 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.

the class AutoscaleManager method processPod.

private void processPod(Pod pod, KubernetesClient client, Set<String> scheduledRuns, List<CompletableFuture<Void>> tasks, Set<String> allPods, Set<String> nodes, Set<String> reassignedNodes) {
    LOGGER.debug("Found an unscheduled pod: {}.", pod.getMetadata().getName());
    Map<String, String> labels = pod.getMetadata().getLabels();
    String runId = labels.get(KubernetesConstants.RUN_ID_LABEL);
    long longId = Long.parseLong(runId);
    if (nodeUpTaskInProgress.contains(longId)) {
        LOGGER.debug("Nodeup task for ID {} is already in progress.", runId);
        return;
    }
    // Check whether node with required RunID is available
    if (nodes.contains(runId)) {
        LOGGER.debug("Node with required ID {} already exists.", runId);
        return;
    }
    // check max nodeup retry count
    // TODO: should we lock here?
    int retryCount = nodeUpAttempts.getOrDefault(longId, 0);
    int nodeUpRetryCount = preferenceManager.getPreference(SystemPreferences.CLUSTER_NODEUP_RETRY_COUNT);
    if (retryCount >= nodeUpRetryCount) {
        LOGGER.debug("Exceeded max nodeup attempts ({}) for run ID {}. Setting run status 'FAILURE'.", retryCount, runId);
        pipelineRunManager.updatePipelineStatusIfNotFinal(longId, TaskStatus.FAILURE, new Date());
        removeNodeUpTask(longId);
        return;
    }
    try {
        RunInstance requiredInstance = getNewRunInstance(runId);
        // check whether aws instance already exists
        RunInstance awsInstance = clusterManager.describeInstance(runId, requiredInstance);
        if (awsInstance != null && awsInstance.getNodeId() != null) {
            LOGGER.debug("Found {} instance for run ID {}.", awsInstance.getNodeId(), runId);
            createNodeForRun(tasks, runId, requiredInstance);
            return;
        }
        List<String> freeNodes = nodes.stream().filter(nodeId -> !allPods.contains(nodeId) && !reassignedNodes.contains(nodeId) && isNodeAvailable(client, nodeId)).collect(Collectors.toList());
        LOGGER.debug("Found {} free nodes.", freeNodes.size());
        // Try to reassign one of idle nodes
        for (String previousId : freeNodes) {
            LOGGER.debug("Found free node ID {}.", previousId);
            RunInstance previousInstance = getPreviousRunInstance(previousId);
            if (clusterManager.requirementsMatch(requiredInstance, previousInstance)) {
                LOGGER.debug("Reassigning node ID {} to run {}.", previousId, runId);
                boolean successfullyReassigned = clusterManager.reassignNode(previousId, runId);
                if (successfullyReassigned) {
                    scheduledRuns.add(runId);
                    pipelineRunManager.updateRunInstance(longId, previousInstance);
                    reassignedNodes.add(previousId);
                    return;
                }
            }
        }
        // Check max cluster capacity
        int currentClusterSize = getCurrentClusterSize(client);
        NodeList nodeList = getAvailableNodes(client);
        Integer maxClusterSize = preferenceManager.getPreference(SystemPreferences.CLUSTER_MAX_SIZE);
        if (currentClusterSize > maxClusterSize) {
            LOGGER.debug("Exceeded maximum cluster size {} - current size {}.", maxClusterSize, currentClusterSize);
            return;
        }
        if (currentClusterSize == maxClusterSize && preferenceManager.getPreference(SystemPreferences.CLUSTER_KILL_NOT_MATCHING_NODES)) {
            LOGGER.debug("Current cluster size {} has reached limit {}. Checking free nodes.", currentClusterSize, maxClusterSize);
            List<String> nonMatchingFreeNodes = freeNodes.stream().filter(id -> !reassignedNodes.contains(id)).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(nonMatchingFreeNodes)) {
                String nodeId = nonMatchingFreeNodes.get(0);
                // to remove node from free
                reassignedNodes.add(nodeId);
                LOGGER.debug("Scaling down unused node {}.", nodeId);
                clusterManager.scaleDown(nodeId);
            } else {
                LOGGER.debug("Exceeded maximum cluster size {}.", nodeList.getItems().size() + nodeUpTaskInProgress.size());
                LOGGER.debug("Leaving pending run {}.", runId);
                return;
            }
        }
        int nodeUpTasksSize = nodeUpTaskInProgress.size();
        int maxNodeUpThreads = preferenceManager.getPreference(SystemPreferences.CLUSTER_NODEUP_MAX_THREADS);
        if (nodeUpTasksSize >= maxNodeUpThreads) {
            LOGGER.debug("Exceeded maximum node up tasks queue size {}.", nodeUpTasksSize);
            return;
        }
        scheduledRuns.add(runId);
        createNodeForRun(tasks, runId, requiredInstance);
    } catch (GitClientException | CmdExecutionException | IllegalArgumentException e) {
        LOGGER.error("Failed to create node for run {}.", runId);
        LOGGER.error("Failed to get pipeline configuration: " + e.getMessage(), e);
    }
}
Also used : GitClientException(com.epam.pipeline.exception.git.GitClientException) Date(java.util.Date) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ParallelExecutorService(com.epam.pipeline.manager.parallel.ParallelExecutorService) Service(org.springframework.stereotype.Service) Duration(java.time.Duration) Map(java.util.Map) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Node(io.fabric8.kubernetes.api.model.Node) PodCondition(io.fabric8.kubernetes.api.model.PodCondition) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) NodeCondition(io.fabric8.kubernetes.api.model.NodeCondition) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) AbstractSchedulingManager(com.epam.pipeline.manager.scheduling.AbstractSchedulingManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Pod(io.fabric8.kubernetes.api.model.Pod) Set(java.util.Set) Instant(java.time.Instant) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) NodeList(io.fabric8.kubernetes.api.model.NodeList) Objects(java.util.Objects) Config(io.fabric8.kubernetes.client.Config) List(java.util.List) CmdExecutionException(com.epam.pipeline.exception.CmdExecutionException) PodList(io.fabric8.kubernetes.api.model.PodList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) NumberUtils(org.apache.commons.lang3.math.NumberUtils) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Collections(java.util.Collections) NodeList(io.fabric8.kubernetes.api.model.NodeList) GitClientException(com.epam.pipeline.exception.git.GitClientException) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) Date(java.util.Date) CmdExecutionException(com.epam.pipeline.exception.CmdExecutionException)

Aggregations

GitClientException (com.epam.pipeline.exception.git.GitClientException)23 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 URISyntaxException (java.net.URISyntaxException)11 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)10 URI (java.net.URI)10 RestTemplate (org.springframework.web.client.RestTemplate)10 List (java.util.List)7 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)7 HashMap (java.util.HashMap)6 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)5 IOException (java.io.IOException)5 Date (java.util.Date)5 Autowired (org.springframework.beans.factory.annotation.Autowired)4 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)3 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)3 GitProject (com.epam.pipeline.entity.git.GitProject)3 GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)3 Revision (com.epam.pipeline.entity.pipeline.Revision)3 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)3 TaskGraphVO (com.epam.pipeline.controller.vo.TaskGraphVO)2