@Test public void testDoDeploy() throws Exception { assertNull(dataSetDefRegistry.getDataSetDef("salesPerYearAutoDeploy")); dataSetDefDeployer.deploy(dataSetsDir); FileOutputStream doDeploy = new FileOutputStream(new File(dataSetsDir, "salesPerYear.dset.deploy")); doDeploy.write("".getBytes()); doDeploy.flush(); doDeploy.close(); Thread.sleep(2000); DataSetDef def = dataSetDefRegistry.getDataSetDef("salesPerYearAutoDeploy"); assertNotNull(def); verify(registryListener).onDataSetDefRegistered(def); }
protected synchronized void doDeploy() { if (!StringUtils.isBlank(directory)) { File[] files = new File(directory).listFiles(_deployFilter); if (files != null) { for (File f : files) { try { f.delete(); File dsetFile = new File(f.getAbsolutePath().replace(".deploy", "")); if (!dsetFile.exists()) continue; FileReader fileReader = new FileReader(dsetFile); String json = IOUtils.toString(fileReader); DataSetDef def = jsonMarshaller.fromJson(json); if (StringUtils.isBlank(def.getUUID())) def.setUUID(dsetFile.getName()); if (def instanceof CSVDataSetDef) { CSVDataSetDef csvDef = (CSVDataSetDef) def; File csvFile = getCSVFile(csvDef); if (csvFile != null) { csvDef.setFilePath(csvFile.getAbsolutePath()); } else { log.error("Data set CSV file not found: " + f.getName()); continue; } } DataSetDef existingDef = dataSetDefRegistry.getDataSetDef(def.getUUID()); if (existingDef != null && jsonMarshaller.toJsonString(existingDef).equals(jsonMarshaller.toJsonString(def))) { log.info("Data set already deployed: " + def.getUUID()); } else { dataSetDefRegistry.registerDataSetDef(def, "system", "deploy(" + def.getUUID() + ")"); log.info("Data set deployed: " + def.getUUID()); } } catch (Exception e) { log.error("Data set deployment error: " + f.getName(), e); } } } files = new File(directory).listFiles(_undeployFilter); if (files != null) { for (File f : files) { try { f.delete(); String uuid = f.getName().replace(".undeploy", ""); DataSetDef def = dataSetDefRegistry.getDataSetDef(uuid); if (def != null) { dataSetDefRegistry.removeDataSetDef(uuid, "system", "undeploy(" + uuid + ")"); log.info("Data set deleted: " + def.getName()); } else { log.error("Data set not found: " + uuid); } } catch (Exception e) { log.error("Data set un-deploy error: " + f.getName(), e); } } } } }
DataSetDefDeployer { protected synchronized void doDeploy() { if (!StringUtils.isBlank(directory)) { File[] files = new File(directory).listFiles(_deployFilter); if (files != null) { for (File f : files) { try { f.delete(); File dsetFile = new File(f.getAbsolutePath().replace(".deploy", "")); if (!dsetFile.exists()) continue; FileReader fileReader = new FileReader(dsetFile); String json = IOUtils.toString(fileReader); DataSetDef def = jsonMarshaller.fromJson(json); if (StringUtils.isBlank(def.getUUID())) def.setUUID(dsetFile.getName()); if (def instanceof CSVDataSetDef) { CSVDataSetDef csvDef = (CSVDataSetDef) def; File csvFile = getCSVFile(csvDef); if (csvFile != null) { csvDef.setFilePath(csvFile.getAbsolutePath()); } else { log.error("Data set CSV file not found: " + f.getName()); continue; } } DataSetDef existingDef = dataSetDefRegistry.getDataSetDef(def.getUUID()); if (existingDef != null && jsonMarshaller.toJsonString(existingDef).equals(jsonMarshaller.toJsonString(def))) { log.info("Data set already deployed: " + def.getUUID()); } else { dataSetDefRegistry.registerDataSetDef(def, "system", "deploy(" + def.getUUID() + ")"); log.info("Data set deployed: " + def.getUUID()); } } catch (Exception e) { log.error("Data set deployment error: " + f.getName(), e); } } } files = new File(directory).listFiles(_undeployFilter); if (files != null) { for (File f : files) { try { f.delete(); String uuid = f.getName().replace(".undeploy", ""); DataSetDef def = dataSetDefRegistry.getDataSetDef(uuid); if (def != null) { dataSetDefRegistry.removeDataSetDef(uuid, "system", "undeploy(" + uuid + ")"); log.info("Data set deleted: " + def.getName()); } else { log.error("Data set not found: " + uuid); } } catch (Exception e) { log.error("Data set un-deploy error: " + f.getName(), e); } } } } } }
DataSetDefDeployer { protected synchronized void doDeploy() { if (!StringUtils.isBlank(directory)) { File[] files = new File(directory).listFiles(_deployFilter); if (files != null) { for (File f : files) { try { f.delete(); File dsetFile = new File(f.getAbsolutePath().replace(".deploy", "")); if (!dsetFile.exists()) continue; FileReader fileReader = new FileReader(dsetFile); String json = IOUtils.toString(fileReader); DataSetDef def = jsonMarshaller.fromJson(json); if (StringUtils.isBlank(def.getUUID())) def.setUUID(dsetFile.getName()); if (def instanceof CSVDataSetDef) { CSVDataSetDef csvDef = (CSVDataSetDef) def; File csvFile = getCSVFile(csvDef); if (csvFile != null) { csvDef.setFilePath(csvFile.getAbsolutePath()); } else { log.error("Data set CSV file not found: " + f.getName()); continue; } } DataSetDef existingDef = dataSetDefRegistry.getDataSetDef(def.getUUID()); if (existingDef != null && jsonMarshaller.toJsonString(existingDef).equals(jsonMarshaller.toJsonString(def))) { log.info("Data set already deployed: " + def.getUUID()); } else { dataSetDefRegistry.registerDataSetDef(def, "system", "deploy(" + def.getUUID() + ")"); log.info("Data set deployed: " + def.getUUID()); } } catch (Exception e) { log.error("Data set deployment error: " + f.getName(), e); } } } files = new File(directory).listFiles(_undeployFilter); if (files != null) { for (File f : files) { try { f.delete(); String uuid = f.getName().replace(".undeploy", ""); DataSetDef def = dataSetDefRegistry.getDataSetDef(uuid); if (def != null) { dataSetDefRegistry.removeDataSetDef(uuid, "system", "undeploy(" + uuid + ")"); log.info("Data set deleted: " + def.getName()); } else { log.error("Data set not found: " + uuid); } } catch (Exception e) { log.error("Data set un-deploy error: " + f.getName(), e); } } } } } DataSetDefDeployer();  DataSetDefDeployer(DataSetDefJSONMarshaller jsonMarshaller, DataSetDefRegistry dataSetDefRegistry); }
DataSetDefDeployer { protected synchronized void doDeploy() { if (!StringUtils.isBlank(directory)) { File[] files = new File(directory).listFiles(_deployFilter); if (files != null) { for (File f : files) { try { f.delete(); File dsetFile = new File(f.getAbsolutePath().replace(".deploy", "")); if (!dsetFile.exists()) continue; FileReader fileReader = new FileReader(dsetFile); String json = IOUtils.toString(fileReader); DataSetDef def = jsonMarshaller.fromJson(json); if (StringUtils.isBlank(def.getUUID())) def.setUUID(dsetFile.getName()); if (def instanceof CSVDataSetDef) { CSVDataSetDef csvDef = (CSVDataSetDef) def; File csvFile = getCSVFile(csvDef); if (csvFile != null) { csvDef.setFilePath(csvFile.getAbsolutePath()); } else { log.error("Data set CSV file not found: " + f.getName()); continue; } } DataSetDef existingDef = dataSetDefRegistry.getDataSetDef(def.getUUID()); if (existingDef != null && jsonMarshaller.toJsonString(existingDef).equals(jsonMarshaller.toJsonString(def))) { log.info("Data set already deployed: " + def.getUUID()); } else { dataSetDefRegistry.registerDataSetDef(def, "system", "deploy(" + def.getUUID() + ")"); log.info("Data set deployed: " + def.getUUID()); } } catch (Exception e) { log.error("Data set deployment error: " + f.getName(), e); } } } files = new File(directory).listFiles(_undeployFilter); if (files != null) { for (File f : files) { try { f.delete(); String uuid = f.getName().replace(".undeploy", ""); DataSetDef def = dataSetDefRegistry.getDataSetDef(uuid); if (def != null) { dataSetDefRegistry.removeDataSetDef(uuid, "system", "undeploy(" + uuid + ")"); log.info("Data set deleted: " + def.getName()); } else { log.error("Data set not found: " + uuid); } } catch (Exception e) { log.error("Data set un-deploy error: " + f.getName(), e); } } } } } DataSetDefDeployer();  DataSetDefDeployer(DataSetDefJSONMarshaller jsonMarshaller, DataSetDefRegistry dataSetDefRegistry); DataSetDefRegistry getDataSetDefRegistry(); void setDataSetDefRegistry(DataSetDefRegistry dataSetDefRegistry); DataSetDefJSONMarshaller getJsonMarshaller(); void setJsonMarshaller(DataSetDefJSONMarshaller jsonMarshaller); String getDirectory(); int getScanIntervalInMillis(); void setScanIntervalInMillis(int scanIntervalInMillis); boolean isRunning(); synchronized void deploy(final String dir); synchronized void stop(); File getCSVFile(CSVDataSetDef def); }
DataSetDefDeployer { protected synchronized void doDeploy() { if (!StringUtils.isBlank(directory)) { File[] files = new File(directory).listFiles(_deployFilter); if (files != null) { for (File f : files) { try { f.delete(); File dsetFile = new File(f.getAbsolutePath().replace(".deploy", "")); if (!dsetFile.exists()) continue; FileReader fileReader = new FileReader(dsetFile); String json = IOUtils.toString(fileReader); DataSetDef def = jsonMarshaller.fromJson(json); if (StringUtils.isBlank(def.getUUID())) def.setUUID(dsetFile.getName()); if (def instanceof CSVDataSetDef) { CSVDataSetDef csvDef = (CSVDataSetDef) def; File csvFile = getCSVFile(csvDef); if (csvFile != null) { csvDef.setFilePath(csvFile.getAbsolutePath()); } else { log.error("Data set CSV file not found: " + f.getName()); continue; } } DataSetDef existingDef = dataSetDefRegistry.getDataSetDef(def.getUUID()); if (existingDef != null && jsonMarshaller.toJsonString(existingDef).equals(jsonMarshaller.toJsonString(def))) { log.info("Data set already deployed: " + def.getUUID()); } else { dataSetDefRegistry.registerDataSetDef(def, "system", "deploy(" + def.getUUID() + ")"); log.info("Data set deployed: " + def.getUUID()); } } catch (Exception e) { log.error("Data set deployment error: " + f.getName(), e); } } } files = new File(directory).listFiles(_undeployFilter); if (files != null) { for (File f : files) { try { f.delete(); String uuid = f.getName().replace(".undeploy", ""); DataSetDef def = dataSetDefRegistry.getDataSetDef(uuid); if (def != null) { dataSetDefRegistry.removeDataSetDef(uuid, "system", "undeploy(" + uuid + ")"); log.info("Data set deleted: " + def.getName()); } else { log.error("Data set not found: " + uuid); } } catch (Exception e) { log.error("Data set un-deploy error: " + f.getName(), e); } } } } } DataSetDefDeployer();  DataSetDefDeployer(DataSetDefJSONMarshaller jsonMarshaller, DataSetDefRegistry dataSetDefRegistry); DataSetDefRegistry getDataSetDefRegistry(); void setDataSetDefRegistry(DataSetDefRegistry dataSetDefRegistry); DataSetDefJSONMarshaller getJsonMarshaller(); void setJsonMarshaller(DataSetDefJSONMarshaller jsonMarshaller); String getDirectory(); int getScanIntervalInMillis(); void setScanIntervalInMillis(int scanIntervalInMillis); boolean isRunning(); synchronized void deploy(final String dir); synchronized void stop(); File getCSVFile(CSVDataSetDef def);  }