public <T> T loadAndPrintValidationErrors(InputStream inputStream, BiFunction<ConfigSchema, Boolean, T> resultHandler) throws IOException, SchemaLoaderException { ConvertableSchema<ConfigSchema> configSchema = SchemaLoader.loadConvertableSchemaFromYaml(inputStream); boolean valid = true; if (!configSchema.isValid()) { System.out.println("Found the following errors when parsing the configuration according to its version. (" + configSchema.getVersion() + ")"); configSchema.getValidationIssues().forEach(s -> System.out.println(s)); System.out.println(); valid = false; configSchema.clearValidationIssues(); } else { System.out.println("No errors found when parsing configuration according to its version. (" + configSchema.getVersion() + ")"); } ConfigSchema currentSchema = configSchema.convert(); if (!currentSchema.isValid()) { System.out.println("Found the following errors when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")"); currentSchema.getValidationIssues().forEach(s -> System.out.println(s)); System.out.println(); valid = false; } else if (configSchema.getVersion() == currentSchema.getVersion()) { System.out.println("Configuration was already latest version (" + ConfigSchema.CONFIG_VERSION + ") so no conversion was needed."); } else { System.out.println("No errors found when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")"); } return resultHandler.apply(currentSchema, valid); }
@Override public ConfigSchema apply(final VersionedFlowSnapshot versionedFlowSnapshot) { Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(versionedFlowSnapshot).toMap()); VersionedProcessGroup versionedProcessGroup = versionedFlowSnapshot.getFlowContents(); addVersionedProcessGroup(map, versionedProcessGroup); return new ConfigSchema(map); }
public static void saveConfigSchema(ConfigSchema configSchema, OutputStream output) throws IOException { DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(new ConfigRepresenter(), dumperOptions); Map<String, Object> yamlMap = configSchema.toMap(); try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(output)) { try { yaml.dump(yamlMap, outputStreamWriter); } catch (YAMLException e) { throw new IOException(e); } } } }
public Map<String, Object> toMap() { Map<String, Object> result = mapSupplier.get(); result.put(VERSION, getVersion()); putIfNotNull(result, FLOW_CONTROLLER_PROPS_KEY, flowControllerProperties); putIfNotNull(result, CORE_PROPS_KEY, coreProperties); putIfNotNull(result, FLOWFILE_REPO_KEY, flowfileRepositoryProperties); putIfNotNull(result, CONTENT_REPO_KEY, contentRepositoryProperties); putIfNotNull(result, PROVENANCE_REPO_KEY, provenanceRepositorySchema); putIfNotNull(result, COMPONENT_STATUS_REPO_KEY, componentStatusRepositoryProperties); putIfNotNull(result, SECURITY_PROPS_KEY, securityProperties); result.putAll(processGroupSchema.toMap()); putIfNotNull(result, PROVENANCE_REPORTING_KEY, provenanceReportingProperties); result.put(NIFI_PROPERTIES_OVERRIDES_KEY, nifiPropertiesOverrides); return result; }
public ConfigSchema(Map map, List<String> validationIssues) { validationIssues.stream().forEach(this::addValidationIssue); flowControllerProperties = getMapAsType(map, FLOW_CONTROLLER_PROPS_KEY, FlowControllerSchema.class, TOP_LEVEL_NAME, true); coreProperties = getMapAsType(map, CORE_PROPS_KEY, CorePropertiesSchema.class, TOP_LEVEL_NAME, false); flowfileRepositoryProperties = getMapAsType(map, FLOWFILE_REPO_KEY, FlowFileRepositorySchema.class, TOP_LEVEL_NAME, false); contentRepositoryProperties = getMapAsType(map, CONTENT_REPO_KEY, ContentRepositorySchema.class, TOP_LEVEL_NAME, false); provenanceRepositorySchema = getMapAsType(map, PROVENANCE_REPO_KEY, ProvenanceRepositorySchema.class, TOP_LEVEL_NAME, false); componentStatusRepositoryProperties = getMapAsType(map, COMPONENT_STATUS_REPO_KEY, ComponentStatusRepositorySchema.class, TOP_LEVEL_NAME, false); securityProperties = getMapAsType(map, SECURITY_PROPS_KEY, SecurityPropertiesSchema.class, TOP_LEVEL_NAME, false); provenanceReportingProperties = getMapAsType(map, PROVENANCE_REPORTING_KEY, ProvenanceReportingSchema.class, TOP_LEVEL_NAME, false, false); addIssuesIfNotNull(flowControllerProperties); addIssuesIfNotNull(coreProperties); addIssuesIfNotNull(flowfileRepositoryProperties); addIssuesIfNotNull(contentRepositoryProperties); addIssuesIfNotNull(componentStatusRepositoryProperties); addIssuesIfNotNull(securityProperties); addIssuesIfNotNull(processGroupSchema); addIssuesIfNotNull(provenanceReportingProperties); addIssuesIfNotNull(provenanceRepositorySchema); List<ProcessGroupSchema> allProcessGroups = getAllProcessGroups(processGroupSchema); List<ConnectionSchema> allConnectionSchemas = allProcessGroups.stream().flatMap(p -> p.getConnections().stream()).collect(Collectors.toList()); List<RemoteProcessGroupSchema> allRemoteProcessGroups = allProcessGroups.stream().flatMap(p -> p.getRemoteProcessGroups().stream()).collect(Collectors.toList()); checkForDuplicates(this::addValidationIssue, FOUND_THE_FOLLOWING_DUPLICATE_PROCESSOR_IDS, allProcessorIds); checkForDuplicates(this::addValidationIssue, FOUND_THE_FOLLOWING_DUPLICATE_CONTROLLER_SERVICE_IDS, allControllerServiceIds); checkForDuplicates(this::addValidationIssue, FOUND_THE_FOLLOWING_DUPLICATE_FUNNEL_IDS, allFunnelIds);
@Test public void testVersion1() throws IOException, SchemaLoaderException { ConfigSchema configSchema = getConfigSchema(c2Url + "?class=raspi3&version=1"); assertEquals(3, configSchema.getVersion()); assertEquals("raspi3.v1", configSchema.getFlowControllerProperties().getName()); }
CorePropertiesSchema coreProperties = configSchema.getCoreProperties(); addTextElement(rootNode, "maxTimerDrivenThreadCount", String.valueOf(coreProperties.getMaxConcurrentThreads())); addTextElement(rootNode, "maxEventDrivenThreadCount", String.valueOf(coreProperties.getMaxConcurrentThreads())); FlowControllerSchema flowControllerProperties = configSchema.getFlowControllerProperties(); ProcessGroupSchema processGroupSchema = configSchema.getProcessGroupSchema(); processGroupSchema.setId(ROOT_GROUP); processGroupSchema.setName(flowControllerProperties.getName()); SecurityPropertiesSchema securityProperties = configSchema.getSecurityProperties(); if (securityProperties.useSSL()) { Element controllerServicesNode = doc.getElementById("controllerServices"); ProvenanceReportingSchema provenanceProperties = configSchema.getProvenanceReportingProperties(); if (provenanceProperties != null) { final Element reportingTasksNode = doc.createElement("reportingTasks");
ConvertableSchema<ConfigSchema> configSchema = SchemaLoader.loadConvertableSchemaFromYaml(new FileInputStream(configFile)); ConfigSchema currentSchema = configSchema.convert(); SecurityPropertiesSchema secProps = currentSchema.getSecurityProperties(); newSchema.setSecurityProperties(secProps); readOnlyNewConfig = ByteBuffer.wrap(new Yaml().dump(newSchema.toMap()).getBytes()).asReadOnlyBuffer();
@Test public void testUser3() throws Exception { SSLContext sslContext = loadSslContext("user3"); assertReturnCode("", sslContext, 400); ConfigSchema configSchema = assertReturnCode("?class=raspi2", sslContext, 200); assertEquals("raspi2.v1", configSchema.getFlowControllerProperties().getName()); configSchema = assertReturnCode("?class=raspi3", sslContext, 200); assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName()); }
public static List<ProcessGroupSchema> getAllProcessGroups(ProcessGroupSchema processGroupSchema) { List<ProcessGroupSchema> result = new ArrayList<>(); addProcessGroups(processGroupSchema, result); return result; }
@Test public void testVersion2() throws IOException, SchemaLoaderException { ConfigSchema configSchema = getConfigSchema(c2Url + "?class=raspi3&version=2"); assertEquals(3, configSchema.getVersion()); assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName()); }
@Test public void testUser1() throws Exception { SSLContext sslContext = loadSslContext("user1"); assertReturnCode("", sslContext, 403); ConfigSchema configSchema = assertReturnCode("?class=raspi2", sslContext, 200); assertEquals("raspi2.v1", configSchema.getFlowControllerProperties().getName()); assertReturnCode("?class=raspi3", sslContext, 403); }
private static void addProcessGroups(ProcessGroupSchema processGroupSchema, List<ProcessGroupSchema> result) { result.add(processGroupSchema); processGroupSchema.getProcessGroupSchemas().forEach(p -> addProcessGroups(p, result)); }
@Test public void testCurrentVersion() throws IOException, SchemaLoaderException { ConfigSchema configSchema = getConfigSchema(c2Url + "?class=raspi3"); assertEquals(3, configSchema.getVersion()); assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName()); }
public <T> T loadAndPrintValidationErrors(InputStream inputStream, BiFunction<ConfigSchema, Boolean, T> resultHandler) throws IOException, SchemaLoaderException { ConvertableSchema<ConfigSchema> configSchema = SchemaLoader.loadConvertableSchemaFromYaml(inputStream); boolean valid = true; if (!configSchema.isValid()) { System.out.println("Found the following errors when parsing the configuration according to its version. (" + configSchema.getVersion() + ")"); configSchema.getValidationIssues().forEach(s -> System.out.println(s)); System.out.println(); valid = false; configSchema.clearValidationIssues(); } else { System.out.println("No errors found when parsing configuration according to its version. (" + configSchema.getVersion() + ")"); } ConfigSchema currentSchema = configSchema.convert(); if (!currentSchema.isValid()) { System.out.println("Found the following errors when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")"); currentSchema.getValidationIssues().forEach(s -> System.out.println(s)); System.out.println(); valid = false; } else if (configSchema.getVersion() == currentSchema.getVersion()) { System.out.println("Configuration was already latest version (" + ConfigSchema.CONFIG_VERSION + ") so no conversion was needed."); } else { System.out.println("No errors found when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")"); } return resultHandler.apply(currentSchema, valid); }
@Override public ConfigSchema apply(TemplateDTO templateDTO) { Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(templateDTO).toMap()); FlowSnippetDTO snippet = templateDTO.getSnippet(); addSnippet(map, snippet); return new ConfigSchema(map); }
@Test public void testUser2() throws Exception { SSLContext sslContext = loadSslContext("user2"); assertReturnCode("", sslContext, 403); assertReturnCode("?class=raspi2", sslContext, 403); ConfigSchema configSchema = assertReturnCode("?class=raspi3", sslContext, 200); assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName()); }
@Override public ConfigSchema apply(final VersionedFlowSnapshot versionedFlowSnapshot) { Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(versionedFlowSnapshot).toMap()); VersionedProcessGroup versionedProcessGroup = versionedFlowSnapshot.getFlowContents(); addVersionedProcessGroup(map, versionedProcessGroup); return new ConfigSchema(map); }
@Override public ConfigSchema apply(TemplateDTO templateDTO) { Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(templateDTO).toMap()); FlowSnippetDTO snippet = templateDTO.getSnippet(); addSnippet(map, snippet); return new ConfigSchema(map); }
@Override public ConfigSchema convert() { Map<String, Object> result = mapSupplier.get(); result.put(VERSION, getVersion()); putIfNotNull(result, FLOW_CONTROLLER_PROPS_KEY, flowControllerProperties); putIfNotNull(result, CORE_PROPS_KEY, coreProperties.convert()); putIfNotNull(result, FLOWFILE_REPO_KEY, flowfileRepositoryProperties); putIfNotNull(result, CONTENT_REPO_KEY, contentRepositoryProperties); putIfNotNull(result, PROVENANCE_REPO_KEY, provenanceRepositorySchema); putIfNotNull(result, COMPONENT_STATUS_REPO_KEY, componentStatusRepositoryProperties); putIfNotNull(result, SECURITY_PROPS_KEY, securityProperties); result.putAll(processGroupSchema.toMap()); putIfNotNull(result, PROVENANCE_REPORTING_KEY, provenanceReportingProperties); return new ConfigSchema(result, getValidationIssues()); } }