private String getTagName(Class<?> clazz) { return clazz.getAnnotation(ConfigTag.class).value(); }
private String getTagName() { return profile.getClass().getAnnotation(ConfigTag.class).value(); }
public String getParentDisplayName() { return getParentType().getAnnotation(ConfigTag.class).value(); }
public String getParentDisplayName() { return getParent().getClass().getAnnotation(ConfigTag.class).value(); }
public static List<String> allTasks(ConfigElementImplementationRegistry registry) { List<String> allTasks = new ArrayList<>(); for (Class<? extends Task> task : registry.implementersOf(Task.class)) { AttributeAwareConfigTag attributeAwareConfigTag = task.getAnnotation(AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null && !allTasks.contains(attributeAwareConfigTag.value())) { allTasks.add(attributeAwareConfigTag.value()); } ConfigTag tag = task.getAnnotation(ConfigTag.class); if (tag != null && !allTasks.contains(tag.value())) { allTasks.add(tag.value()); } } return allTasks; }
public String label() { ConfigTag configTag = ConfigCache.annotationFor(aClass, ConfigTag.class); return isEmpty(configTag.label()) ? capitalize(configTag.value()) : configTag.label(); }
private void update(Username currentUser, PipelineConfigs pipelineConfigs, LocalizedOperationResult result, EntityConfigUpdateCommand command) { try { goConfigService.updateConfig(command, currentUser); } catch (Exception e) { if (e instanceof GoConfigInvalidException) { if (!result.hasMessage()) { result.unprocessableEntity(entityConfigValidationFailed(pipelineConfigs.getClass().getAnnotation(ConfigTag.class).value(), pipelineConfigs.getGroup(), e.getMessage())); } } else if (!(e instanceof ConfigUpdateCheckFailedException)) { LOGGER.error(e.getMessage(), e); result.internalServerError(saveFailedWithReason(e.getMessage())); } } }
private void update(Username currentUser, PipelineConfig pipelineConfig, LocalizedOperationResult result, EntityConfigUpdateCommand command) { try { goConfigService.updateConfig(command, currentUser); } catch (Exception e) { if (e instanceof GoConfigInvalidException) { if (!result.hasMessage()) { result.unprocessableEntity(entityConfigValidationFailed(pipelineConfig.getClass().getAnnotation(ConfigTag.class).value(), str(pipelineConfig.name()), e.getMessage())); } } else if (!(e instanceof ConfigUpdateCheckFailedException)) { LOGGER.error(e.getMessage(), e); result.internalServerError(saveFailedWithReason(e.getMessage())); } } }
private void update(Username username, HttpLocalizedOperationResult result, EntityConfigUpdateCommand command, PackageRepository repository) { try { goConfigService.updateConfig(command, username); } catch (Exception e) { if (e instanceof GoConfigInvalidException && !result.hasMessage()) { result.unprocessableEntity(entityConfigValidationFailed(repository.getClass().getAnnotation(ConfigTag.class).value(), repository.getId(), e.getMessage())); } else { if (!result.hasMessage()) { LOGGER.error(e.getMessage(), e); result.internalServerError(saveFailedWithReason("An error occurred while saving the package repository config. Please check the logs for more information.")); } } } }
private void addDescribeOfArguments(StringBuilder builder, ConfigTag configTag, GoConfigFieldWriter field) { if (field.isSubtag() && field.getValue() instanceof Arguments) { closeConfigTag(builder, field); if (field.getValue() instanceof Arguments && ((Arguments) field.getValue()).size() != 0) { for (Argument arg : (Arguments) field.getValue()) { builder.append(String.format("<arg>%s</arg>", arg.getValue())).append("\n"); } builder.append("</" + configTag.value() + ">"); } } }
private void update(EntityConfigUpdateCommand command, EnvironmentConfig config, Username currentUser, HttpLocalizedOperationResult result, String actionFailed) { try { goConfigService.updateConfig(command, currentUser); } catch (Exception e) { if ((e instanceof GoConfigInvalidException) && !result.hasMessage()) { result.unprocessableEntity(entityConfigValidationFailed(config.getClass().getAnnotation(ConfigTag.class).value(), config.name(), e.getMessage())); } else if (!result.hasMessage()) { result.badRequest(LocalizedMessage.composite(actionFailed, e.getMessage())); } } } }
private void update(Username username, PackageDefinition packageDeinition, HttpLocalizedOperationResult result, EntityConfigUpdateCommand command) { try { goConfigService.updateConfig(command, username); } catch (Exception e) { if (e instanceof GoConfigInvalidException && !result.hasMessage()) { result.unprocessableEntity(entityConfigValidationFailed(packageDeinition.getClass().getAnnotation(ConfigTag.class).value(), packageDeinition.getId(), e.getMessage())); } else { if (!result.hasMessage()) { LOGGER.error(e.getMessage(), e); result.internalServerError(saveFailedWithReason("An error occurred while saving the package config. Please check the logs for more information.")); } } } }
private void update(Username username, String repoId, HttpLocalizedOperationResult result, EntityConfigUpdateCommand command) { try { goConfigService.updateConfig(command, username); } catch (Exception e) { if (e instanceof GoConfigInvalidException && !result.hasMessage()) { result.unprocessableEntity(entityConfigValidationFailed(ConfigRepoConfig.class.getAnnotation(ConfigTag.class).value(), repoId, e.getMessage())); } else { if (!result.hasMessage()) { LOGGER.error(e.getMessage(), e); result.internalServerError(saveFailedWithReason("An error occurred while saving the package config. Please check the logs for more information.")); } } } }
protected void update(Username currentUser, M pluginProfile, LocalizedOperationResult result, PluginProfileCommand command) { try { validatePluginProperties(command, pluginProfile); goConfigService.updateConfig(command, currentUser); } catch (Exception e) { if (e instanceof GoConfigInvalidException) { result.unprocessableEntity(entityConfigValidationFailed(pluginProfile.getClass().getAnnotation(ConfigTag.class).value(), pluginProfile.getId(), e.getMessage())); } else { if (!result.hasMessage()) { LOGGER.error(e.getMessage(), e); result.internalServerError(saveFailedWithReason("An error occurred while saving the profile config. Please check the logs for more information.")); } } } } }
public static boolean compare(Element e, Class<?> implementation, ConfigCache configCache) { final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(implementation, AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null) { return compareAttributeAwareConfigTag(e, attributeAwareConfigTag); } ConfigTag configTag = configTag(implementation, configCache); return configTag.value().equals(e.getName()) && e.getNamespace().getURI().equals(configTag.namespaceURI()); }
public void bulkUpdateAgentAttributes(AgentInstances agentInstances, final Username username, final LocalizedOperationResult result, final List<String> uuids, final List<String> resourcesToAdd, final List<String> resourcesToRemove, final List<String> environmentsToAdd, final List<String> environmentsToRemove, final TriState enable) { EntityConfigUpdateCommand<Agents> agentsEntityConfigUpdateCommand = new AgentsEntityConfigUpdateCommand(agentInstances, username, result, uuids, environmentsToAdd, environmentsToRemove, enable, resourcesToAdd, resourcesToRemove, goConfigService); try { goConfigService.updateConfig(agentsEntityConfigUpdateCommand, username); if(result.isSuccessful()){ result.setMessage("Updated agent(s) with uuid(s): [" + StringUtils.join(uuids, ", ") + "]."); } } catch (Exception e) { LOGGER.error("There was an error bulk updating agents", e); if(e instanceof GoConfigInvalidException && !result.hasMessage()) { result.unprocessableEntity(entityConfigValidationFailed(Agents.class.getAnnotation(ConfigTag.class).value(), StringUtils.join(uuids, ","), e.getMessage())); } else if(!result.hasMessage()) { result.internalServerError("Server error occured. Check log for details."); } } }
private Element child(Element e, ConfigTag tag) { return e.getChild(tag.value(), Namespace.getNamespace(tag.namespacePrefix(), tag.namespaceURI())); }
private boolean atElement() { AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(aClass, AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null) { final String attribute = attributeAwareConfigTag.attribute(); bombIf(isBlank(attribute), format("Type '%s' has invalid configuration for @AttributeAwareConfigTag. It must have `attribute` with non blank value.", aClass.getName())); bombIf(!hasAttribute(attribute), format("Expected attribute `%s` to be present for %s.", attribute, configUtil.elementOutput(e))); return configUtil.atTag(e, attributeAwareConfigTag.value()); } ConfigTag configTag = annotationFor(aClass, ConfigTag.class); if (configTag == null) { return false; } String tag = configTag.value(); return configUtil.atTag(e, tag); }
private void updateConfig(Username currentUser, LocalizedOperationResult result, EntityConfigUpdateCommand<AdminsConfig> command) { try { goConfigService.updateConfig(command, currentUser); } catch (Exception e) { if (e instanceof GoConfigInvalidException) { String adminsTag = AdminsConfig.class.getAnnotation(ConfigTag.class).value(); String errors = deDuplicatedErrors(((GoConfigInvalidException) e).getCruiseConfig().getAllErrors()); result.unprocessableEntity(LocalizedMessage.entityConfigValidationFailed(adminsTag, errors)); } else { if (!result.hasMessage()) { LOGGER.error(e.getMessage(), e); result.internalServerError(saveFailedWithReason("An error occurred while updating the System Admins. Please check the logs for more information.")); } } } }
private static Element elementFor(Class<?> aClass, ConfigCache configCache) { final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(aClass, AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null) { final Element element = new Element(attributeAwareConfigTag.value(), namespaceFor(attributeAwareConfigTag)); element.setAttribute(attributeAwareConfigTag.attribute(), attributeAwareConfigTag.attributeValue()); return element; } ConfigTag configTag = annotationFor(aClass, ConfigTag.class); if (configTag == null) throw bomb(format("Cannot get config tag for {0}", aClass)); return new Element(configTag.value(), namespaceFor(configTag)); }