private List<String> populateList(Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> packageUsageInPipelines) { ArrayList<String> pipleines = new ArrayList<>(); for(String key: packageUsageInPipelines.keySet()) { List<Pair<PipelineConfig, PipelineConfigs>> pairs = packageUsageInPipelines.get(key); for(Pair<PipelineConfig, PipelineConfigs> pair : pairs) { pipleines.add(pair.first().getName().toLower()); } } return pipleines; }
public void execute(JobExecutionContext context) { JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); BuildCauseProducerService buildCauseProducerService = (BuildCauseProducerService) jobDataMap.get(BUILD_CAUSE_PRODUCER_SERVICE); MaintenanceModeService maintenanceModeService = (MaintenanceModeService) jobDataMap.get(MAINTENANCE_MODE_SERVICE); PipelineConfig pipelineConfig = (PipelineConfig) jobDataMap.get(PIPELINE_CONFIG); if (maintenanceModeService.isMaintenanceMode()) { LOG.debug("[Maintenance Mode] GoCD server is in 'maintenance' mode, skipping scheduling of timer triggered pipeline: '{}'.", pipelineConfig.getName()); return; } buildCauseProducerService.timerSchedulePipeline(pipelineConfig, new ServerHealthStateOperationResult()); } }
private List<String> populateList(Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> packageUsageInPipelines) { ArrayList<String> pipelinesReferringPackages = new ArrayList<>(); List<Pair<PipelineConfig, PipelineConfigs>> pairs = packageUsageInPipelines.get(packageDefinition.getId()); if (pairs != null) { for (Pair<PipelineConfig, PipelineConfigs> pair : pairs) { pipelinesReferringPackages.add(pair.first().getName().toLower()); } } return pipelinesReferringPackages; }
private Permissions resolvePermissionsForPipelineGroup(PipelineConfigs pipelineGroup, GoDashboardPipelines allPipelines) { for (PipelineConfig pipelineConfig : pipelineGroup) { GoDashboardPipeline goDashboardPipeline = allPipelines.find(pipelineConfig.getName()); if (goDashboardPipeline != null) { return goDashboardPipeline.permissions(); } } return null; }
@Override public ArrayList<CaseInsensitiveString> pipelinesAssociatedWithTemplate(CaseInsensitiveString templateName) { ArrayList<CaseInsensitiveString> pipelines = new ArrayList<>(); if (templateName != null) { for (PipelineConfig pipelineConfig : getAllPipelineConfigs()) { if (pipelineConfig.hasTemplate() && pipelineConfig.getTemplateName().equals(templateName)) { pipelines.add(pipelineConfig.getName()); } } } return pipelines; }
public List<GoDashboardPipeline> allPipelines(CruiseConfig config) { List<CaseInsensitiveString> allPipelineNames = config.getAllPipelineNames(); HashSet<CaseInsensitiveString> currentPipelineNames = new HashSet<>(allPipelineNames); Collection<CaseInsensitiveString> pipelinesToRemove = Sets.difference(lastKnownPipelineNames, currentPipelineNames); Collection<CaseInsensitiveString> pipelinesToAdd = Sets.difference(currentPipelineNames, lastKnownPipelineNames); if (!pipelinesToAdd.isEmpty()) { historyForDashboard.addAll(loadHistoryForPipelines(new ArrayList<>(CaseInsensitiveString.toStringList(pipelinesToAdd)))); } for (CaseInsensitiveString pipelineNameToRemove : new ArrayList<>(pipelinesToRemove)) { clearEntryFor(pipelineNameToRemove); } lastKnownPipelineNames = currentPipelineNames; LOGGER.debug("Loading permissions from authority"); final Map<CaseInsensitiveString, Permissions> pipelinesAndTheirPermissions = permissionsAuthority.pipelinesAndTheirPermissions(); final List<GoDashboardPipeline> pipelines = new ArrayList<>(1024); LOGGER.debug("Populating dashboard pipelines"); config.accept((PipelineGroupVisitor) group -> group.accept(pipelineConfig -> { long start = System.currentTimeMillis(); Permissions permissions = permissionsFor(pipelineConfig, pipelinesAndTheirPermissions); pipelines.add(createGoDashboardPipeline(pipelineConfig, permissions, historyForDashboard, group)); LOGGER.debug("It took {}ms to process pipeline {}", (System.currentTimeMillis() - start), pipelineConfig.getName()); })); LOGGER.debug("Done populating dashboard pipelines"); this.everLoadedCurrentState = true; return pipelines; }
private void validateParams(PipelineConfig pipelineConfig, ParamsConfig paramsConfig) { for (ParamConfig paramConfig : paramsConfig) { if (!pipelineConfig.getParams().hasParamNamed(paramConfig.getName())) { this.addError("params", String.format("The param '%s' is not defined in pipeline '%s'", paramConfig.getName(), pipelineConfig.getName())); } } }
public Map<String, Map> artifactIdToPluginIdForFetchPluggableArtifact(String stagePatent, String currentPipelineName, String currentStageName) { final List<PipelineConfig> pipelineConfigs = stagePatent.equals("templates") ? getAllPipelineConfigs() : pipelinesForFetchArtifacts(currentPipelineName); Map<String, Map> allArtifacts = new HashMap<>(); pipelineConfigs.forEach(pipelineConfig -> { final String pipelineName = pipelineConfig.getName().toString(); final HashMap<String, Map> artifactsInPipeline = new HashMap<>(); allArtifacts.put(pipelineName, artifactsInPipeline); final boolean isCurrentPipeline = pipelineName.equalsIgnoreCase(currentPipelineName); final List<StageConfig> stageConfigs = isCurrentPipeline ? pipelineConfig.allStagesBefore(new CaseInsensitiveString(currentStageName)) : pipelineConfig.getStages(); stageConfigs.forEach(stageConfig -> { final String stageName = stageConfig.name().toString(); artifactsInPipeline.put(stageName, new HashMap<String, Map>()); stageConfig.getJobs().forEach(jobConfig -> { artifactsInPipeline.get(stageName).put(jobConfig.name().toString(), jobConfig.artifactConfigs().getPluggableArtifactConfigs().stream().collect(toMap(PluggableArtifactConfig::getId, c -> { final ArtifactStore artifactStore = artifactStores().find(c.getStoreId()); return artifactStore == null ? null : artifactStore.getPluginId(); }))); }); }); }); return allArtifacts; }
public GoDashboardPipeline pipelineFor(PipelineConfig pipelineConfig, PipelineConfigs groupConfig) { List<String> pipelineNames = CaseInsensitiveString.toStringList(Collections.singletonList(pipelineConfig.getName())); PipelineInstanceModels pipelineHistoryForDashboard = loadHistoryForPipelines(pipelineNames); syncHistoryForDashboard(pipelineHistoryForDashboard, pipelineConfig.name()); Permissions permissions = permissionsAuthority.permissionsForPipeline(pipelineConfig.name()); return createGoDashboardPipeline(pipelineConfig, permissions, pipelineHistoryForDashboard, groupConfig); }
private void haltIfEntityBySameNameInRequestExists(PipelineConfig pipelineConfig) { if (pipelineConfigService.getPipelineConfig(pipelineConfig.name().toString()) == null) { return; } pipelineConfig.addError("name", LocalizedMessage.resourceAlreadyExists("pipeline", pipelineConfig.name().toString())); throw haltBecauseEntityAlreadyExists(jsonWriter(pipelineConfig), "pipeline", pipelineConfig.getName()); } }
jobsUsingElasticProfile.add(new ElasticProfileUsage(pipelineConfig.getName().toString() , stage.name().toString() , job.name().toString()
@Override public Map<CaseInsensitiveString, Map<CaseInsensitiveString, Authorization>> templatesWithAssociatedPipelines() { if (allTemplatesWithAssociatedPipelines == null) { allTemplatesWithAssociatedPipelines = new AllTemplatesWithAssociatedPipelines(); for (PipelineTemplateConfig templateConfig : getTemplates()) { if (!allTemplatesWithAssociatedPipelines.containsKey(templateConfig.name())) { allTemplatesWithAssociatedPipelines.put(templateConfig.name(), new HashMap<>()); } } for (PipelineConfigs pipelineConfigs : getGroups()) { List<PipelineConfig> pipelines = pipelineConfigs.getPipelines(); for (PipelineConfig pipeline : pipelines) { if (pipeline.hasTemplate()) { Map<CaseInsensitiveString, Authorization> authorizationMap = allTemplatesWithAssociatedPipelines.get(pipeline.getTemplateName()); authorizationMap.put(pipeline.getName(), pipelineConfigs.getAuthorization()); } } } } return allTemplatesWithAssociatedPipelines; }
@Override public boolean canContinue(CruiseConfig cruiseConfig) { String groupName = goConfigService.findGroupNameByPipeline(pipelineConfig.name()); if (goConfigService.groups().hasGroup(groupName) && !goConfigService.isUserAdminOfGroup(currentUser.getUsername(), groupName)) { result.forbidden(LocalizedMessage.forbiddenToDelete("Pipeline", pipelineConfig.getName()), HealthStateType.forbidden()); return false; } return true; } }
public static void toJSON(OutputWriter pipelineWriter, PipelineConfig pipeline) { pipelineWriter.addLinks(linksWriter -> linksWriter .addLink("self", Routes.PipelineConfig.name(pipeline.getName().toString())) .addAbsoluteLink("doc", Routes.PipelineConfig.DOC) .addLink("find", Routes.PipelineConfig.find()) ); pipelineWriter.add("name", pipeline.name()); } }
public String update(Request req, Response res) { PipelineConfig existingPipelineConfig = fetchEntityFromConfig(req.params("pipeline_name")); PipelineConfig pipelineConfigFromRequest = buildEntityFromRequestBody(req); if (isRenameAttempt(existingPipelineConfig, pipelineConfigFromRequest)) { throw haltBecauseRenameOfEntityIsNotSupported("pipelines"); } haltIfPipelineIsDefinedRemotely(existingPipelineConfig); if (isPutRequestStale(req, existingPipelineConfig)) { throw haltBecauseEtagDoesNotMatch("pipeline", existingPipelineConfig.getName()); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); pipelineConfigService.updatePipelineConfig(SessionUtils.currentUsername(), pipelineConfigFromRequest, etagFor(existingPipelineConfig), result); return handleCreateOrUpdateResponse(req, res, pipelineConfigFromRequest, result); }
public String exportPipeline(Request req, Response res) { PipelineConfig pipelineConfig = pipelineConfigFromRequest(req); String pluginId = requiredQueryParam(req, "plugin_id"); String groupName = configService.findGroupNameByPipeline(pipelineConfig.getName()); if (!crPluginService.isConfigRepoPlugin(pluginId)) { throw haltBecauseOfReason("Plugin `%s` is not a config-repo plugin.", pluginId); } if (!crPluginService.supportsPipelineExport(pluginId)) { throw haltBecauseOfReason("Plugin `%s` does not support pipeline config export.", pluginId); } ConfigRepoPlugin repoPlugin = crPlugin(pluginId); String etag = repoPlugin.etagForExport(pipelineConfig, groupName); if (fresh(req, etag)) { return notModified(res); } else { setEtagHeader(res, etag); ExportedConfig export = repoPlugin.pipelineExport(pipelineConfig, groupName); res.header("Content-Type", export.getContentType()); res.header("Content-Disposition", format("attachment; filename=\"%s\"", export.getFilename())); return export.getContent(); } }
public static void toJSON(OutputWriter jsonWriter, PipelineConfig pipelineConfig) { jsonWriter.addLinks(linksWriter -> linksWriter .addLink("self", Routes.PipelineConfig.name(pipelineConfig.getName().toString())) .addAbsoluteLink("doc", Routes.PipelineConfig.DOC) .addLink("find", Routes.PipelineConfig.find())); // This is needed for the case when there are no materials defined. Refer to pipeline_config_representer.rb#152 pipelineConfig.errors().addAll(pipelineConfig.materialConfigs().errors()); if (!pipelineConfig.errors().isEmpty()) { jsonWriter.addChild("errors", errorWriter -> { HashMap<String, String> errorMapping = new HashMap<>(); errorMapping.put("labelTemplate", "label_template"); errorMapping.put("params", "parameters"); errorMapping.put("variables", "environment_variables"); errorMapping.put("trackingTool", "tracking_tool"); new ErrorGetter(errorMapping).toJSON(errorWriter, pipelineConfig); }); } jsonWriter.add("label_template", pipelineConfig.getLabelTemplate()); jsonWriter.add("lock_behavior", pipelineConfig.getLockBehavior()); jsonWriter.add("name", pipelineConfig.name()); jsonWriter.add("template", pipelineConfig.getTemplateName()); writeOrigin(jsonWriter, pipelineConfig.getOrigin()); jsonWriter.addChildList("parameters", paramsWriter -> ParamRepresenter.toJSONArray(paramsWriter, pipelineConfig.getParams())); jsonWriter.addChildList("environment_variables", envVarsWriter -> EnvironmentVariableRepresenter.toJSON(envVarsWriter, pipelineConfig.getVariables())); jsonWriter.addChildList("materials", materialsWriter -> MaterialRepresenter.toJSONArray(materialsWriter, pipelineConfig.materialConfigs())); writeStages(jsonWriter, pipelineConfig); writeTrackingTool(jsonWriter, pipelineConfig); writeTimer(jsonWriter, pipelineConfig.getTimer()); }