Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
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();
      }
    }