@Override public void upgradeProject() throws IOException { //let's check if we have legacy config directories, then we copy them to their new places, and rename the previous ones as .old Path entityConfigDir = this.projectDir.resolve("entity-config"); Path hubInternalConfigDir = this.projectDir.resolve("hub-internal-config"); Path userConfigDir = this.projectDir.resolve("user-config"); //and now what we want to name the old directories so they're not copied over again in another update Path oldEntityConfigDir = this.projectDir.resolve("entity-config.old"); Path oldHubInternalConfigDir = this.projectDir.resolve("hub-internal-config.old"); Path oldUserConfigDir = this.projectDir.resolve("user-config.old"); //obsolete database/server/role names in hub-internal-config from 3.0 Set<String> obsoleteFiles = Stream.of("trace-database.json", "triggers-database.json", "schemas-database.json", "trace-server.json", "data-hub-role.json").collect(Collectors.toSet()); //if the entity-config directory exists, we'll copy it to the src/main/entity-config upgradeProjectDir(entityConfigDir, getEntityConfigDir(), oldEntityConfigDir); upgradeHubInternalConfig(hubInternalConfigDir, oldHubInternalConfigDir, obsoleteFiles ); upgradeUserConfig(userConfigDir, oldUserConfigDir, obsoleteFiles); /*If the upgrade path is 3.0 -> 4.0.x -> 4.1.0 or 4.0.0 -> 4.1.0, the obsolete files have to be removed, * else, they will cause deployment to fail */ deleteObsoleteDatabaseFilesFromHubInternalConfig(); deleteObsoleteServerFilesFromHubInternalConfig(); deleteObsoleteDatabaseFilesFromMlConfig(); }
@Override public Path getHubServersDir() { return getHubConfigDir().resolve("servers"); }
addPathRangeIndexesToJobDatabase(rootNode); +getHubDatabaseDir().resolve(f.getFileName()).toFile().getAbsolutePath()); FileUtils.writeStringToFile(getHubDatabaseDir().resolve(f.getFileName()).toFile(), dbFile); } catch (IOException e) { logger.error("Unable to update "+f.getFileName()); if (path.toLowerCase().equals("modules-database.json")) { logger.info("Writing "+ f.toFile().getAbsolutePath() +" to " +getUserDatabaseDir().resolve(f.getFileName()).toFile().getAbsolutePath()); FileUtils.copyFile(f.toFile(), getUserDatabaseDir().resolve(f.getFileName()).toFile()); String dbFile = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rootNode); logger.info("Writing "+ f.toFile().getAbsolutePath() +" to " +getUserDatabaseDir().resolve(f.getFileName()).toFile().getAbsolutePath()); FileUtils.writeStringToFile(getUserDatabaseDir().resolve(f.getFileName()).toFile(), dbFile); } catch (IOException e) { logger.error("Unable to update "+f.getFileName()); +getHubServersDir().resolve(f.getFileName()).toFile().getAbsolutePath()); FileUtils.writeStringToFile(getHubServersDir().resolve(f.getFileName()).toFile(), serverFile); } catch (IOException e) { logger.error("Unable to update "+f.getFileName()); try { logger.info("Writing "+ f.toFile().getAbsolutePath() +" to " +getUserServersDir().resolve(f.getFileName()).toFile().getAbsolutePath()); FileUtils.copyFile(f.toFile(), getUserServersDir().resolve(f.getFileName()).toFile()); } catch (IOException e) {
@Override public boolean isInitialized() { File buildGradle = this.projectDir.resolve("build.gradle").toFile(); File gradleProperties = this.projectDir.resolve("gradle.properties").toFile(); File hubConfigDir = getHubConfigDir().toFile(); File userConfigDir = getUserConfigDir().toFile(); File databasesDir = getHubDatabaseDir().toFile(); File serversDir = getHubServersDir().toFile(); File securityDir = getHubSecurityDir().toFile(); boolean newConfigInitialized = hubConfigDir.exists() && hubConfigDir.isDirectory() && userConfigDir.exists() && userConfigDir.isDirectory() && databasesDir.exists() && databasesDir.isDirectory() && serversDir.exists() && serversDir.isDirectory() && securityDir.exists() && securityDir.isDirectory(); return buildGradle.exists() && gradleProperties.exists() && newConfigInitialized; }
@Test public void upgrade300To403ToCurrentVersion() throws Exception { final String projectPath = "build/tmp/upgrade-projects/dhf403from300"; final File projectDir = Paths.get(projectPath).toFile(); FileUtils.deleteDirectory(projectDir); FileUtils.copyDirectory(Paths.get("src/test/resources/upgrade-projects/dhf403from300").toFile(), projectDir); HubProjectImpl hubProject = new HubProjectImpl(); hubProject.createProject(projectPath); // The tokens map doesn't seem to matter for what we're testing here hubProject.init(new HashMap<>()); hubProject.upgradeProject(); File srcDir = new File(projectDir, "src"); File mainDir = new File(srcDir, "main"); File internalConfigDir = new File(mainDir, "hub-internal-config"); verifyInternalDatabases(internalConfigDir); verifyInternalServers(internalConfigDir); File configDir = new File(mainDir, "ml-config"); verifyUserDatabases(configDir); verifyUserServers(configDir); }
private void updateManagerEntity() { Path managerDir = project.getEntityDir("manager"); assertTrue(managerDir.toFile().exists()); File targetFile = managerDir.resolve("manager.entity.json").toFile(); FileUtil.copy(getResourceStream("scaffolding-test/manager2.entity.json"), targetFile); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } targetFile.setLastModified(System.currentTimeMillis()); }
@Override public Path getEntityDatabaseDir() { return getEntityConfigDir().resolve("databases"); }
/** * In the upgrade from 3.x to 4.x, the job-database.json file is copied to its new location, but it also needs * several indexes added to it. * * @param rootNode */ private void addPathRangeIndexesToJobDatabase(ObjectNode rootNode) { if (rootNode.get("range-path-index") == null) { if (logger.isInfoEnabled()) { logger.info("Adding path range indexes to job-database.json"); } ArrayNode indexes = rootNode.putArray("range-path-index"); addStringPathRangeIndex(indexes, "/trace/hasError"); addStringPathRangeIndex(indexes, "/trace/flowType"); addStringPathRangeIndex(indexes, "/trace/jobId"); addStringPathRangeIndex(indexes, "/trace/traceId"); addStringPathRangeIndex(indexes, "/trace/identifier"); ObjectNode node = indexes.addObject(); node.put("scalar-type", "dateTime"); node.put("path-expression", "/trace/created"); node.put("collation", ""); node.put("range-value-positions", false); node.put("invalid-values", "reject"); } }
@Test public void upgrade300ToCurrentVersion() throws Exception { final String projectPath = "build/tmp/upgrade-projects/dhf300"; final File projectDir = Paths.get(projectPath).toFile(); FileUtils.deleteDirectory(projectDir); FileUtils.copyDirectory(Paths.get("src/test/resources/upgrade-projects/dhf300").toFile(), projectDir); HubProjectImpl hubProject = new HubProjectImpl(); hubProject.createProject(projectPath); // The tokens map doesn't seem to matter for what we're testing here hubProject.init(new HashMap<>()); hubProject.upgradeProject(); File srcDir = new File(projectDir, "src"); File mainDir = new File(srcDir, "main"); File internalConfigDir = new File(mainDir, "hub-internal-config"); verifyInternalDatabases(internalConfigDir); verifyInternalServers(internalConfigDir); File configDir = new File(mainDir, "ml-config"); verifyUserDatabases(configDir); verifyUserServers(configDir); }
private void installMappings() { Path employeeDir = project.getEntityDir("employee"); employeeDir.toFile().mkdirs(); assertTrue(employeeDir.toFile().exists()); FileUtil.copy(getResourceStream("scaffolding-test/employee.entity.json"), employeeDir.resolve("employee.entity.json").toFile()); Path managerDir = project.getEntityDir("manager"); managerDir.toFile().mkdirs(); assertTrue(managerDir.toFile().exists()); FileUtil.copy(getResourceStream("scaffolding-test/manager.entity.json"), managerDir.resolve("manager.entity.json").toFile()); }
@Override public Path getHubDatabaseDir() { return getHubConfigDir().resolve("databases"); }
@Override public Path getHubSecurityDir() { return getHubConfigDir().resolve("security"); }
@Override public Path getHubSchemasDir() { return getHubConfigDir().resolve("schemas"); }