@Test public void testUpdateJobCluster() { SimpleCachedFileStorageProvider sProvider = new SimpleCachedFileStorageProvider(); String clusterName = "testUpdateJobCluster"; JobClusterDefinitionImpl jobClusterDefn = createFakeJobClusterDefn(clusterName, Lists.newArrayList()); IJobClusterMetadata jobCluster = new JobClusterMetadataImpl.Builder().withLastJobCount(0).withJobClusterDefinition(jobClusterDefn).build(); try { sProvider.createJobCluster(jobCluster); Optional<IJobClusterMetadata> readDataOp = sProvider.loadJobCluster(clusterName); if(readDataOp.isPresent()) { assertEquals(clusterName, readDataOp.get().getJobClusterDefinition().getName()); assertEquals(0, readDataOp.get().getJobClusterDefinition().getLabels().size()); } else { fail(); } List<Label> labels = Lists.newArrayList(); labels.add(new Label("label1", "label1value")); jobClusterDefn = createFakeJobClusterDefn(clusterName, labels); IJobClusterMetadata jobClusterUpdated = new JobClusterMetadataImpl.Builder().withLastJobCount(0).withJobClusterDefinition(jobClusterDefn).build(); sProvider.updateJobCluster(jobClusterUpdated); readDataOp = sProvider.loadJobCluster(clusterName); if(readDataOp.isPresent()) { assertEquals(clusterName, readDataOp.get().getJobClusterDefinition().getName()); assertEquals(1, readDataOp.get().getJobClusterDefinition().getLabels().size()); } else { fail(); } } catch(Exception e) { e.printStackTrace(); fail(); } }
@Override public void updateJobCluster(IJobClusterMetadata jobCluster) { String name = jobCluster.getJobClusterDefinition().getName(); File tmpFile = new File(JOB_CLUSTERS_DIR + "/" + name); logger.info("Updating job cluster " + name + " to file " + tmpFile.getAbsolutePath()); try { if (!tmpFile.exists()) { throw new InvalidNamedJobException(name + " does not exist"); } tmpFile.delete(); tmpFile.createNewFile(); PrintWriter pwrtr = new PrintWriter(tmpFile); mapper.writeValue(pwrtr, jobCluster); } catch (IOException | InvalidNamedJobException e) { throw new RuntimeException(e); } }
SimpleCachedFileStorageProvider implements IMantisStorageProvider { @Override public void updateJobCluster(IJobClusterMetadata jobCluster) { String name = jobCluster.getJobClusterDefinition().getName(); File tmpFile = new File(JOB_CLUSTERS_DIR + "/" + name); logger.info("Updating job cluster " + name + " to file " + tmpFile.getAbsolutePath()); try { if (!tmpFile.exists()) { throw new InvalidNamedJobException(name + " does not exist"); } tmpFile.delete(); tmpFile.createNewFile(); PrintWriter pwrtr = new PrintWriter(tmpFile); mapper.writeValue(pwrtr, jobCluster); } catch (IOException | InvalidNamedJobException e) { throw new RuntimeException(e); } } }
SimpleCachedFileStorageProvider implements IMantisStorageProvider { @Override public void updateJobCluster(IJobClusterMetadata jobCluster) { String name = jobCluster.getJobClusterDefinition().getName(); File tmpFile = new File(JOB_CLUSTERS_DIR + "/" + name); logger.info("Updating job cluster " + name + " to file " + tmpFile.getAbsolutePath()); try { if (!tmpFile.exists()) { throw new InvalidNamedJobException(name + " does not exist"); } tmpFile.delete(); tmpFile.createNewFile(); PrintWriter pwrtr = new PrintWriter(tmpFile); mapper.writeValue(pwrtr, jobCluster); } catch (IOException | InvalidNamedJobException e) { throw new RuntimeException(e); } } SimpleCachedFileStorageProvider();  SimpleCachedFileStorageProvider(boolean cleanupExistingData); }
SimpleCachedFileStorageProvider implements IMantisStorageProvider { @Override public void updateJobCluster(IJobClusterMetadata jobCluster) { String name = jobCluster.getJobClusterDefinition().getName(); File tmpFile = new File(JOB_CLUSTERS_DIR + "/" + name); logger.info("Updating job cluster " + name + " to file " + tmpFile.getAbsolutePath()); try { if (!tmpFile.exists()) { throw new InvalidNamedJobException(name + " does not exist"); } tmpFile.delete(); tmpFile.createNewFile(); PrintWriter pwrtr = new PrintWriter(tmpFile); mapper.writeValue(pwrtr, jobCluster); } catch (IOException | InvalidNamedJobException e) { throw new RuntimeException(e); } } SimpleCachedFileStorageProvider();  SimpleCachedFileStorageProvider(boolean cleanupExistingData); @Override void archiveJob(String jobId); @Override Optional<IMantisJobMetadata> loadArchivedJob(String jobId); Optional<IMantisJobMetadata> loadActiveJob(String jobId); Optional<IMantisJobMetadata> loadArchiveJob(String jobId); @Override void storeMantisStage(IMantisStageMetadata msmd); @Override void updateMantisStage(IMantisStageMetadata msmd); @Override void storeWorker(IMantisWorkerMetadata workerMetadata); @Override void storeWorkers(String jobId, List<IMantisWorkerMetadata> workers); @Override void storeAndUpdateWorkers(IMantisWorkerMetadata existingWorker, IMantisWorkerMetadata newWorker); @Override void updateWorker(IMantisWorkerMetadata mwmd); @Override List<IMantisJobMetadata> loadAllJobs(); @Override Observable<IMantisJobMetadata> loadAllArchivedJobs(); @Override List<IJobClusterMetadata> loadAllJobClusters(); Optional<IJobClusterMetadata> loadJobCluster(String clusterName); @Override List<CompletedJob> loadAllCompletedJobs(); @Override void archiveWorker(IMantisWorkerMetadata mwmd); @Override void createJobCluster(IJobClusterMetadata jobCluster); @Override void deleteJobCluster(String name); @Override void updateJobCluster(IJobClusterMetadata jobCluster); @Override void storeNewJob(IMantisJobMetadata jobMetadata); @Override void updateJob(IMantisJobMetadata jobMetadata); void deleteAllFiles(); @Override void deleteJob(String jobId); @Override void storeCompletedJobForCluster(String name, CompletedJob job); @Override void removeCompletedJobForCluster(String name, String jobId); @Override void setActiveVmAttributeValuesList(List<String> vmAttributesList); @Override List<String> initActiveVmAttributeValuesList(); @Override List<IMantisWorkerMetadata> getArchivedWorkers(String jobId); }
SimpleCachedFileStorageProvider implements IMantisStorageProvider { @Override public void updateJobCluster(IJobClusterMetadata jobCluster) { String name = jobCluster.getJobClusterDefinition().getName(); File tmpFile = new File(JOB_CLUSTERS_DIR + "/" + name); logger.info("Updating job cluster " + name + " to file " + tmpFile.getAbsolutePath()); try { if (!tmpFile.exists()) { throw new InvalidNamedJobException(name + " does not exist"); } tmpFile.delete(); tmpFile.createNewFile(); PrintWriter pwrtr = new PrintWriter(tmpFile); mapper.writeValue(pwrtr, jobCluster); } catch (IOException | InvalidNamedJobException e) { throw new RuntimeException(e); } } SimpleCachedFileStorageProvider();  SimpleCachedFileStorageProvider(boolean cleanupExistingData); @Override void archiveJob(String jobId); @Override Optional<IMantisJobMetadata> loadArchivedJob(String jobId); Optional<IMantisJobMetadata> loadActiveJob(String jobId); Optional<IMantisJobMetadata> loadArchiveJob(String jobId); @Override void storeMantisStage(IMantisStageMetadata msmd); @Override void updateMantisStage(IMantisStageMetadata msmd); @Override void storeWorker(IMantisWorkerMetadata workerMetadata); @Override void storeWorkers(String jobId, List<IMantisWorkerMetadata> workers); @Override void storeAndUpdateWorkers(IMantisWorkerMetadata existingWorker, IMantisWorkerMetadata newWorker); @Override void updateWorker(IMantisWorkerMetadata mwmd); @Override List<IMantisJobMetadata> loadAllJobs(); @Override Observable<IMantisJobMetadata> loadAllArchivedJobs(); @Override List<IJobClusterMetadata> loadAllJobClusters(); Optional<IJobClusterMetadata> loadJobCluster(String clusterName); @Override List<CompletedJob> loadAllCompletedJobs(); @Override void archiveWorker(IMantisWorkerMetadata mwmd); @Override void createJobCluster(IJobClusterMetadata jobCluster); @Override void deleteJobCluster(String name); @Override void updateJobCluster(IJobClusterMetadata jobCluster); @Override void storeNewJob(IMantisJobMetadata jobMetadata); @Override void updateJob(IMantisJobMetadata jobMetadata); void deleteAllFiles(); @Override void deleteJob(String jobId); @Override void storeCompletedJobForCluster(String name, CompletedJob job); @Override void removeCompletedJobForCluster(String name, String jobId); @Override void setActiveVmAttributeValuesList(List<String> vmAttributesList); @Override List<String> initActiveVmAttributeValuesList(); @Override List<IMantisWorkerMetadata> getArchivedWorkers(String jobId);  }