@Override public final boolean containsJob(TenantContext tenantContext, String jobName) { if (!jobName.endsWith(_fileExtension)) { jobName = jobName + _fileExtension; } final RepositoryFile file = tenantContext.getJobFolder().getFile(jobName); if (file == null) { return false; } return true; } }
/** * Delete file from repository * * @param instanceId * @return */ public boolean remove(String instanceId) { writeLock.lock(); try { RepositoryFile configFile = componentsFolder.getFile(instanceId); if (configFile == null) { logger.info("Component with id: {} is not in store.", instanceId); return false; } configFile.delete(); logger.info("Component {} was removed.", instanceId); } finally { writeLock.unlock(); } return true; }
/** * Read file from repository and transform it to object * * @param instanceId * @return */ public ComponentStoreHolder get(String instanceId) { logger.info("Read component with id: {}", instanceId); readLock.lock(); final ComponentStoreHolder[] conf = new ComponentStoreHolder[1]; try { RepositoryFile configFile = componentsFolder.getFile(instanceId); if (configFile == null) { return null; } configFile.readFile(new Action<InputStream>() { @Override public void run(InputStream arg) throws Exception { String theString = IOUtils.toString(arg); conf[0] = objectMapper.readValue(theString, ComponentStoreHolder.class); } }); } finally { readLock.unlock(); } return conf[0]; }
private RepositoryFile createOrUpdateFile(final RepositoryFolder folder, final String filename, final Action<OutputStream> writeAction) { RepositoryFile file = folder.getFile(filename); if (file == null) { file = folder.createFile(filename, writeAction); } else { file.writeFile(writeAction); } return file; } }
@Override public RepositoryNode getRepositoryNode(final String path) { RepositoryFolder folder = this; final String[] pathParts = path.split("/"); for (int i = 0; i < pathParts.length - 1; i++) { final String pathPart = pathParts[i]; if (!pathPart.isEmpty()) { folder = folder.getFolder(pathPart); if (folder == null) { return null; } } } final String lastPart = pathParts[pathParts.length - 1]; if (lastPart.isEmpty()) { return folder; } final RepositoryFile file = folder.getFile(lastPart); if (file == null) { return folder.getFolder(lastPart); } return file; } }
private boolean isUploadedFilePresent(String tenant, String fileName) { final TenantContext context = _contextFactory.getContext(tenant); final RepositoryFolder jobsFolder = context.getJobFolder(); final RepositoryFile file = jobsFolder.getFile(fileName); return (file != null && file.getSize() > 0); }
public ConfigurationCache(InjectionManagerFactory injectionManagerFactory, TenantContext tenantContext, Repository repository) { _injectionManagerFactory = injectionManagerFactory; _tenantContext = tenantContext; _repository = repository; final RepositoryFolder tenantFolder = _tenantContext.getTenantRootFolder(); RepositoryFile file = tenantFolder.getFile(DataCleanerConfigurationImpl.DEFAULT_FILENAME); if (file == null) { file = tenantFolder.createFile(DataCleanerConfigurationImpl.DEFAULT_FILENAME, new WriteDefaultTenantConfigurationAction()); } _file = file; }
@RequestMapping(method = RequestMethod.POST, produces = "application/json") @ResponseBody @RolesAllowed({ SecurityRoles.JOB_EDITOR }) public Map<String, String> deleteJob(@PathVariable("tenant") final String tenant, @PathVariable("job") String jobName) { logger.info("Request payload: {} - {}", tenant, jobName); jobName = jobName.replaceAll("\\+", " "); final TenantContext tenantContext = _contextFactory.getContext(tenant); final JobContext job = tenantContext.getJob(jobName); RepositoryFile file = job.getJobFile(); file.delete(); final RepositoryFile scheduleFile = tenantContext.getJobFolder().getFile( jobName + SchedulingServiceImpl.EXTENSION_SCHEDULE_XML); if (scheduleFile != null) { scheduleFile.delete(); } _eventPublisher.publishEvent(new JobDeletionEvent(this, tenant, jobName)); final Map<String, String> response = new TreeMap<String, String>(); response.put("job", jobName); response.put("action", "delete"); logger.debug("Response payload: {}", response); return response; }
@Override public T getJobContext(TenantContext tenantContext, JobIdentifier job) { final String jobName = job.getName(); final String jobFilename = getJobFilename(jobName); final RepositoryFile file = tenantContext.getJobFolder().getFile(jobFilename); if (file == null) { throw new IllegalArgumentException("No such job: " + jobName); } return getJobContext(tenantContext, file); }
folder = rootFolder; final RepositoryFile existingFile = folder.getFile(filename); final Action<OutputStream> writeCallback = new Action<OutputStream>() { @Override
resultFile = resultsFolder.getFile(resultName);
public ExecutionLoggerImpl(ExecutionLog execution, RepositoryFolder resultFolder, ApplicationEventPublisher eventPublisher) { _execution = execution; _resultFolder = resultFolder; _eventPublisher = eventPublisher; _erronuous = new AtomicBoolean(false); _executionLogWriter = new JaxbExecutionLogWriter(); _log = new StringBuilder(); final String resultId = execution.getResultId(); final String logFilename = resultId + FileFilters.ANALYSIS_EXECUTION_LOG_XML.getExtension(); final RepositoryFile existingLogFile = resultFolder.getFile(logFilename); if (existingLogFile == null) { _logFile = resultFolder.createFile(logFilename, new Action<OutputStream>() { @Override public void run(OutputStream out) throws Exception { _executionLogWriter.write(_execution, out); } }); } else { _logFile = existingLogFile; } }
/** * Store configuration to repository in JSON * * @param configuration */ public void store(final ComponentStoreHolder configuration) { logger.info("Store component with id: {}", configuration.getInstanceId()); writeLock.lock(); RepositoryFile configFile = componentsFolder.getFile(configuration.getInstanceId()); if (configFile != null) { // I must delete old file. configFile.delete(); } try { componentsFolder.createFile(configuration.getInstanceId(), new Action<OutputStream>() { @Override public void run(OutputStream fileOutput) throws Exception { String jsonConf = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString( configuration); InputStream jsonConfStream = IOUtils.toInputStream(jsonConf); FileHelper.copy(jsonConfStream, fileOutput); } }); } finally { writeLock.unlock(); } }
if (jobFolder.getFile(newJobFilename) != null) { throw new IllegalArgumentException("The job '" + newJobFilename + "' already exists.");
private void renameSchedule(final RepositoryFile oldScheduleFile, final String nameInput, final RepositoryFolder jobFolder) { final String newScheduleFilename = nameInput + SchedulingServiceImpl.EXTENSION_SCHEDULE_XML; final Action<OutputStream> writeScheduleAction = new Action<OutputStream>() { @Override public void run(final OutputStream out) throws Exception { oldScheduleFile.readFile(new Action<InputStream>() { @Override public void run(final InputStream in) throws Exception { FileHelper.copy(in, out); } }); } }; final RepositoryFile newScheduleFile = jobFolder.getFile(newScheduleFilename); if (newScheduleFile == null) { jobFolder.createFile(newScheduleFilename, writeScheduleAction); } else { newScheduleFile.writeFile(writeScheduleAction); } oldScheduleFile.delete(); } }
final DashboardGroup group = new DashboardGroup(folder.getName()); final RepositoryFile descriptionFile = folder.getFile("description.txt"); if (descriptionFile == null) { logger.debug("No description file for timeline group: {}", group);
@Override public ExecutionLog getExecution(TenantIdentifier tenant, ExecutionIdentifier executionIdentifier) throws DCSecurityException { if (executionIdentifier == null) { return null; } final String resultId = executionIdentifier.getResultId(); if (resultId == null) { return null; } final TenantContext tenantContext = _tenantContextFactory.getContext(tenant); final RepositoryFolder resultFolder = tenantContext.getResultFolder(); final RepositoryFile file = resultFolder.getFile(resultId + FileFilters.ANALYSIS_EXECUTION_LOG_XML .getExtension()); if (file == null) { logger.warn("No execution with result id: " + resultId); return null; } JobIdentifier jobIdentifier = JobIdentifier.fromExecutionIdentifier(executionIdentifier); return readExecutionLogFile(file, jobIdentifier, tenant, 3); }
final RepositoryFile oldFile = resultFolder.getFile(oldExecutionLogFilename); if (oldFile == null) { logger.warn("Could not find execution log for (old) result filename: {}. Skipping execution log update.", final RepositoryFile newFile = resultFolder.getFile(newFilename); final Action<OutputStream> writeAction = new Action<OutputStream>() { @Override
final RepositoryFile scheduleFile = jobsFolder.getFile(jobName + EXTENSION_SCHEDULE_XML); final JaxbScheduleReader reader = new JaxbScheduleReader();
@Override public ScheduleDefinition updateSchedule(final TenantIdentifier tenant, final ScheduleDefinition scheduleDefinition) { initializeSchedule(scheduleDefinition); final String jobName = scheduleDefinition.getJob().getName(); final TenantContext context = _tenantContextFactory.getContext(tenant); final RepositoryFolder jobsFolder = context.getJobFolder(); final String filename = jobName + EXTENSION_SCHEDULE_XML; final RepositoryFile file = jobsFolder.getFile(filename); final Action<OutputStream> writeAction = new Action<OutputStream>() { @Override public void run(OutputStream out) throws Exception { JaxbScheduleWriter writer = new JaxbScheduleWriter(); writer.write(scheduleDefinition, out); } }; if (file == null) { jobsFolder.createFile(filename, writeAction); } else { file.writeFile(writeAction); } return scheduleDefinition; }