Beispiel #1
0
  @Test
  public void shouldFailToAddDuplicatePipelineAlreadyDefinedInConfigRepo() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig localCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            localCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "remote_group"));

    PipelineConfig pipe2Dup = PipelineConfigMother.pipelineConfig("pipe2");
    try {
      cruiseConfig.addPipeline("doesNotMatterWhichGroup", pipe2Dup);
    } catch (Exception ex) {
      assertThat(
          ex.getMessage(),
          is(
              "Pipeline called 'pipe2' is already defined in configuration repository http://some.git at 1234fed"));
    }

    assertThat(cruiseConfig.allPipelines().size(), is(2));
    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe2")), is(true));

    assertThat(localCruiseConfig.allPipelines().size(), is(1));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe1")), is(true));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe2")), is(false));
  }
Beispiel #2
0
  public ConfigUpdateResponse updateConfigFromUI(
      final UpdateConfigFromUI command,
      final String md5,
      Username username,
      final LocalizedOperationResult result) {
    UiBasedConfigUpdateCommand updateCommand =
        new UiBasedConfigUpdateCommand(md5, command, result, cachedGoPartials);
    UpdatedNodeSubjectResolver updatedConfigResolver = new UpdatedNodeSubjectResolver();
    try {
      ConfigSaveState configSaveState = updateConfig(updateCommand);
      return latestUpdateResponse(
          command, updateCommand, updatedConfigResolver, clonedConfigForEdit(), configSaveState);
    } catch (ConfigFileHasChangedException e) {
      CruiseConfig updatedConfig = handleMergeException(md5, updateCommand);
      result.conflict(LocalizedMessage.string("SAVE_FAILED_WITH_REASON", e.getMessage()));
      return latestUpdateResponse(
          command, updateCommand, new OldNodeSubjectResolver(), updatedConfig, null);
    } catch (ConfigUpdateCheckFailedException e) {
      // result is already set
    } catch (Exception e) {
      ConfigMergeException mergeException = ExceptionUtils.getCause(e, ConfigMergeException.class);
      ConfigMergePostValidationException mergePostValidationException =
          ExceptionUtils.getCause(e, ConfigMergePostValidationException.class);
      if (mergeException != null || mergePostValidationException != null) {
        CruiseConfig updatedConfig = handleMergeException(md5, updateCommand);
        result.conflict(LocalizedMessage.string("SAVE_FAILED_WITH_REASON", e.getMessage()));
        return latestUpdateResponse(
            command, updateCommand, new OldNodeSubjectResolver(), updatedConfig, null);
      }
      GoConfigInvalidException ex = ExceptionUtils.getCause(e, GoConfigInvalidException.class);
      if (ex != null) {
        CruiseConfig badConfig = ex.getCruiseConfig();
        setMD5(md5, badConfig);
        Validatable node = updatedConfigResolver.getNode(command, updateCommand.cruiseConfig());
        BasicCruiseConfig.copyErrors(command.updatedNode(badConfig), node);
        result.badRequest(LocalizedMessage.string("SAVE_FAILED"));
        return new ConfigUpdateResponse(
            badConfig,
            node,
            subjectFromNode(command, updatedConfigResolver, node),
            updateCommand,
            null);
      } else {
        result.badRequest(LocalizedMessage.string("SAVE_FAILED_WITH_REASON", e.getMessage()));
      }
    }

    CruiseConfig newConfigSinceNoOtherConfigExists = clonedConfigForEdit();
    setMD5(md5, newConfigSinceNoOtherConfigExists);
    return latestUpdateResponse(
        command,
        updateCommand,
        new OldNodeSubjectResolver(),
        newConfigSinceNoOtherConfigExists,
        null);
  }
Beispiel #3
0
 @Test
 public void addPipeline_shouldFailToAddPipelineToMainWhenItExistsInPartialConfig() {
   pipelines =
       new BasicPipelineConfigs(
           "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
   pipelines.setOrigin(new FileConfigOrigin());
   BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
   cruiseConfig =
       new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2"));
   try {
     cruiseConfig.addPipeline("group_main", PipelineConfigMother.pipelineConfig("pipe2"));
     fail("should have thrown when trying to add pipe2 when it already exists in partial config");
   } catch (Exception ex) {
     assertThat(
         ex.getMessage(),
         containsString("Pipeline called 'pipe2' is already defined in configuration repository"));
   }
 }
Beispiel #4
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()));
   }
 }
Beispiel #5
0
    public GoConfigValidity saveXml(String xmlPartial, String expectedMd5) {
      GoConfigValidity hasValidRequest = checkValidity();
      if (!hasValidRequest.isValid()) {
        return hasValidRequest;
      }

      try {
        return GoConfigValidity.valid(updatePartial(xmlPartial, expectedMd5));
      } catch (JDOMParseException jsonException) {
        return GoConfigValidity.invalid(
                String.format("%s - %s", INVALID_CRUISE_CONFIG_XML, jsonException.getMessage()))
            .fromConflict();
      } catch (ConfigMergePreValidationException e) {
        return invalid(e).mergePreValidationError();
      } catch (Exception e) {
        if (e.getCause() instanceof ConfigMergePostValidationException) {
          return GoConfigValidity.invalid(e.getCause().getMessage()).mergePostValidationError();
        }
        if (e.getCause() instanceof ConfigMergeException) {
          return GoConfigValidity.invalid(e.getCause().getMessage()).mergeConflict();
        }
        return GoConfigValidity.invalid(e).fromConflict();
      }
    }