@Override public JsonElement serialize(List<PipelineConfigs> src, Type typeOfSrc, JsonSerializationContext context) { JsonObject serialized = new JsonObject(); for (PipelineConfigs group : src) { final List<PipelineConfig> pipelines = group.getPipelines(); if (!pipelines.isEmpty()) { List<CaseInsensitiveString> pipelineNames = pipelines.stream().map(PipelineConfig::name).collect(Collectors.toList()); serialized.add(group.getGroup(), context.serialize(pipelineNames)); } } return serialized; } }
private String calcPipelinesDataEtag(Username username, List<PipelineConfigs> pipelineConfigs) { final HashMap<String, List<CaseInsensitiveString>> pipelinesDataSegment = new HashMap<>(); for (PipelineConfigs group : pipelineConfigs) { final List<PipelineConfig> pipelines = group.getPipelines(); if (!pipelines.isEmpty()) { List<CaseInsensitiveString> pipelineNames = pipelines.stream().map(PipelineConfig::name).collect(Collectors.toList()); pipelinesDataSegment.put(group.getGroup(), pipelineNames); } } return DigestUtils.md5Hex(StringUtils.joinWith("/", username.getUsername(), pipelinesDataSegment)); } }
public ModelAndView index(Request request, Response response) { HashMap<String, String> locals = new HashMap<String, String>() {{ List<String> pipelines = new ArrayList<>(); pipelineConfigService.viewableGroupsFor(SessionUtils.currentUsername()).forEach( (PipelineConfigs config) -> config.getPipelines().forEach( (p) -> pipelines.add(p.name().toString()) ) ); put("viewTitle", "Analytics"); put("pipelines", GSON.toJson(pipelines)); }}; return new ModelAndView(locals, "analytics/index.vm"); }
public List<PipelineConfig> getAllPipelineConfigsForEditForUser(Username username) { ArrayList<PipelineConfig> pipelineConfigs = new ArrayList<>(); List<String> groupsForUser = getConfigForEditing().getGroupsForUser(username.getUsername(), rolesForUser(username.getUsername())); for (String groupName : groupsForUser) { pipelineConfigs.addAll(getAllPipelinesForEditInGroup(groupName).getPipelines()); } return pipelineConfigs; }
@Override public List<PipelineConfig> getAllLocalPipelineConfigs(boolean excludeMembersOfRemoteEnvironments) { List<PipelineConfig> locals = new ArrayList<>(); PipelineGroups localGroups = BasicCruiseConfig.this.groups.getLocal(); for (PipelineConfigs pipelineConfigs : localGroups) { if (pipelineConfigs.getOrigin() instanceof UIConfigOrigin) { //then we have injected this so that UI has a piece to edit // we want to keep it only if there is something added if (!pipelineConfigs.isEmpty()) { for (PipelineConfig pipelineConfig : pipelineConfigs.getPipelines()) { if (excludeMembersOfRemoteEnvironments && BasicCruiseConfig.this.getEnvironments().isPipelineAssociatedWithRemoteEnvironment(pipelineConfig.name())) continue; locals.add(pipelineConfig); } } } else { //origin is local file for (PipelineConfig pipelineConfig : pipelineConfigs.getPipelines()) { if (excludeMembersOfRemoteEnvironments && BasicCruiseConfig.this.getEnvironments().isPipelineAssociatedWithRemoteEnvironment(pipelineConfig.name())) continue; locals.add(pipelineConfig); } } } return locals; }
@Test public void shouldGetAllPipelinesList() { PipelineConfig pipeline1 = PipelineConfigMother.pipelineConfig("pipeline1"); PipelineConfig pipeline2 = PipelineConfigMother.pipelineConfig("pipeline2"); PipelineConfigs group = createWithPipelines(pipeline1, pipeline2); assertThat(group.getPipelines(), hasItem(pipeline1)); assertThat(group.getPipelines(), hasItem(pipeline2)); }
@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; }
@Test public void shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig2_WhenPipelinesInDefaultGroup() { BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("pipeline1"); // pipeline1 is in xml and in config repo - this is an error at merged scope PartialConfig remotePart = PartialConfigMother.withPipelineInGroup("pipeline1", "defaultGroup"); remotePart.setOrigin(new RepoConfigOrigin()); BasicCruiseConfig merged = new BasicCruiseConfig(cruiseConfig, remotePart); List<ConfigErrors> allErrors = merged.validateAfterPreprocess(); assertThat(remotePart.getGroups().get(0).getPipelines().get(0).errors().size(), is(1)); assertThat(allErrors.size(), is(2)); assertThat(allErrors.get(0).on("name"), is("You have defined multiple pipelines named 'pipeline1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]")); assertThat(allErrors.get(1).on("name"), is("You have defined multiple pipelines named 'pipeline1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]")); }
@Test public void shouldDeepCloneObject(){ BasicCruiseConfig config = GoConfigMother.configWithPipelines("p1", "p2"); BasicCruiseConfig cloned = new GoConfigCloner().deepClone(config); assertThat(cloned.getGroups().size(), is(1)); assertThat(cloned.getGroups().get(0).getPipelines().size(), is(2)); } }
public static void toJSON(OutputWriter jsonWriter, PipelineConfigs group) { jsonWriter.addLinks(linksWriter -> linksWriter .addLink("self", Routes.PipelineGroupsAdmin.name(group.getGroup())) .addAbsoluteLink("doc", Routes.PipelineGroupsAdmin.DOC) .addLink("find", Routes.PipelineGroupsAdmin.find()) ); jsonWriter.add("name", group.getGroup()); jsonWriter.addChild("authorization", childWriter -> AuthorizationRepresenter.toJSON(childWriter, group.getAuthorization())); jsonWriter.addChildList("pipelines", pipelinesWriter -> PipelineConfigSummaryRepresenter.toJSON(pipelinesWriter, group.getPipelines())); }
@Test public void shouldLoadPartialConfigWithPipeline() throws Exception { String partialConfigWithPipeline = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<pipelines group=\"first\">\n" + "<pipeline name=\"pipeline\">\n" + " <materials>\n" + " <hg url=\"/hgrepo\"/>\n" + " </materials>\n" + " <stage name=\"mingle\">\n" + " <jobs>\n" + " <job name=\"functional\">\n" + " <artifacts>\n" + " <log src=\"artifact1.xml\" dest=\"cruise-output\" />\n" + " </artifacts>\n" + " </job>\n" + " </jobs>\n" + " </stage>\n" + "</pipeline>\n" + "</pipelines>\n" + "</cruise>\n"; PartialConfig partialConfig = xmlLoader.fromXmlPartial(partialConfigWithPipeline, PartialConfig.class); assertThat(partialConfig.getGroups().size(), is(1)); PipelineConfig pipeline = partialConfig.getGroups().get(0).getPipelines().get(0); assertThat(pipeline.name(), is(new CaseInsensitiveString("pipeline"))); assertThat(pipeline.size(), is(1)); assertThat(pipeline.findBy(new CaseInsensitiveString("mingle")).jobConfigByInstanceName("functional", true), is(notNullValue())); }