示例#1
0
 public void modifyEnvironments(List<AgentInstance> agents, List<TriStateSelection> selections) {
   GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
   for (AgentInstance agentInstance : agents) {
     String uuid = agentInstance.getUuid();
     if (hasAgent(uuid)) {
       for (TriStateSelection selection : selections) {
         command.addCommand(
             new ModifyEnvironmentCommand(uuid, selection.getValue(), selection.getAction()));
       }
     }
   }
   updateConfig(command);
 }
示例#2
0
 public void modifyRolesAndUserAdminPrivileges(
     final List<String> users,
     final TriStateSelection adminPrivilege,
     final List<TriStateSelection> roleSelections,
     LocalizedOperationResult result) {
   Users allUsers = userDao.allUsers();
   for (String user : users) {
     if (!allUsers.containsUserNamed(user)) {
       result.badRequest(LocalizedMessage.string("USER_DOES_NOT_EXIST_IN_DB", user));
       return;
     }
   }
   try {
     final GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
     command.addCommand(goConfigService.modifyRolesCommand(users, roleSelections));
     command.addCommand(goConfigService.modifyAdminPrivilegesCommand(users, adminPrivilege));
     goConfigService.updateConfig(command);
   } catch (Exception e) {
     result.badRequest(LocalizedMessage.string("INVALID_ROLE_NAME", e.getMessage()));
   }
 }
  private void setupPipelines(Integer numberOfPipelinesToBeCreated) throws Exception {
    String groupName = "jumbo";
    String configFile = "<FULL PATH TO YOUR CONFIG FILE>";
    String xml = FileUtil.readContentFromFile(new File(configFile));
    xml = goConfigMigration.upgradeIfNecessary(xml);
    goConfigService
        .fileSaver(false)
        .saveConfig(xml, goConfigService.getConfigForEditing().getMd5());
    LOGGER.info(
        String.format(
            "Total number of pipelines in this config: %s",
            goConfigService.getConfigForEditing().allPipelines().size()));
    if (goConfigService.getConfigForEditing().hasPipelineGroup(groupName)) {
      ((BasicPipelineConfigs) goConfigService.getConfigForEditing().findGroup(groupName)).clear();
    }
    final CruiseConfig configForEditing = goConfigService.getConfigForEditing();
    for (int i = 0; i < numberOfPipelinesToBeCreated; i++) {
      JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("job"));
      StageConfig stageConfig =
          new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(jobConfig));
      PipelineConfig pipelineConfig =
          new PipelineConfig(
              new CaseInsensitiveString("pipeline" + i),
              new MaterialConfigs(new GitMaterialConfig("FOO")),
              stageConfig);
      configForEditing.addPipeline(groupName, pipelineConfig);
    }

    goConfigService.updateConfig(
        new UpdateConfigCommand() {
          @Override
          public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            return configForEditing;
          }
        });
  }