private void removeJob(long id) throws NotFoundException, ServiceRegistryException { synchronized (jobs) { if (!jobs.containsKey(id)) throw new NotFoundException("No job with ID '" + id + "' found"); jobs.remove(id); } }
public Annotation getAnnotation(long id) throws NotFoundException { EntityManager em = null; try { em = emf.createEntityManager(); AnnotationImpl a = em.find(AnnotationImpl.class, id); if (a == null) { throw new NotFoundException("Annotation '" + id + "' not found"); } else { return a; } } finally { if (em != null) em.close(); } }
@Override public Organization getOrganization(final URL url) throws NotFoundException { Organization org = cache.get(url); if (org == null) throw new NotFoundException(); return org; }
@Override public Organization getOrganization(final String id) throws NotFoundException { Organization org = cache.get(id); if (org == null) throw new NotFoundException(); return org; }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#disableHost(String) */ @Override public void disableHost(String host) throws ServiceRegistryException, NotFoundException { if (hosts.containsKey(host)) { hosts.get(host).setActive(false); } else { throw new NotFoundException("The host named " + host + " was not found"); } }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#enableHost(String) */ @Override public void enableHost(String host) throws ServiceRegistryException, NotFoundException { if (hosts.containsKey(host)) { hosts.get(host).setActive(true); } else { throw new NotFoundException("The host named " + host + " was not found"); } }
/** * {@inheritDoc} * * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getFromCollection(java.lang.String, * java.lang.String) */ @Override public InputStream getFromCollection(String collectionId, String fileName) throws NotFoundException, IOException { File f = getFileFromCollection(collectionId, fileName); if (f == null || !f.isFile()) { throw new NotFoundException("Unable to locate " + f + " in the working file repository"); } logger.debug("Attempting to read file {}", f.getAbsolutePath()); return new FileInputStream(f); }
/** * @see org.opencastproject.kernel.security.persistence.OrganizationDatabase#getOrganization(java.lang.String) */ @Override public Organization getOrganization(String id) throws NotFoundException, OrganizationDatabaseException { EntityManager em = null; try { em = emf.createEntityManager(); JpaOrganization entity = getOrganizationEntity(id, em); if (entity == null) throw new NotFoundException(); return entity; } finally { if (em != null) em.close(); } }
@Override public Organization getOrganizationByHost(String host, int port) throws OrganizationDatabaseException, NotFoundException { EntityManager em = null; try { em = emf.createEntityManager(); Query q = em.createNamedQuery("Organization.findByHost"); q.setParameter("serverName", host); q.setParameter("port", port); return (JpaOrganization) q.getSingleResult(); } catch (NoResultException e) { throw new NotFoundException(); } catch (Exception e) { throw new OrganizationDatabaseException(e); } finally { if (em != null) em.close(); } }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#getJob(long) */ @Override public Job getJob(long id) throws NotFoundException, ServiceRegistryException { synchronized (jobs) { String serializedJob = jobs.get(id); if (serializedJob == null) throw new NotFoundException(Long.toString(id)); try { return JobParser.parseJob(serializedJob); } catch (IOException e) { throw new IllegalStateException("Error unmarshaling job", e); } } }
/** * {@inheritDoc} * * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getCollectionSize(java.lang.String) */ @Override public long getCollectionSize(String id) throws NotFoundException { File collectionDir = null; try { collectionDir = getCollectionDirectory(id, false); if (collectionDir == null || !collectionDir.canRead()) throw new NotFoundException("Can not find collection " + id); } catch (IOException e) { // can be ignored, since we don't want the directory to be created, so it will never happen } File[] files = collectionDir.listFiles(MD5_FINAME_FILTER); if (files == null) throw new IllegalArgumentException("Collection " + id + " is not a directory"); return files.length; }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#registerService(java.lang.String, java.lang.String, * java.lang.String, boolean) */ @Override public ServiceRegistration registerService(String serviceType, String host, String path, boolean jobProducer) throws ServiceRegistryException { HostRegistrationInMemory hostRegistration = hosts.get(host); if (hostRegistration == null) { throw new ServiceRegistryException(new NotFoundException("Host " + host + " was not found")); } List<ServiceRegistrationInMemoryImpl> servicesOnHost = services.get(host); if (servicesOnHost == null) { servicesOnHost = new ArrayList<ServiceRegistrationInMemoryImpl>(); services.put(host, servicesOnHost); } ServiceRegistrationInMemoryImpl registration = new ServiceRegistrationInMemoryImpl(serviceType, host, path, jobProducer); servicesOnHost.add(registration); return registration; }
/** * Updates the load factor for a node * @param host * The host to update * @param modifier * The modifier to apply to the load */ public void updateNodeLoad(String host, float modifier) throws NotFoundException { if (!nodeLoads.containsKey(host)) { throw new NotFoundException("Host " + host + " not in this load object"); } NodeLoad current = nodeLoads.get(host); current.setLoadFactor(current.getLoadFactor() + modifier); }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#setMaintenanceStatus(java.lang.String, boolean) */ @Override public void setMaintenanceStatus(String host, boolean maintenance) throws NotFoundException { List<ServiceRegistrationInMemoryImpl> servicesOnHost = services.get(host); if (!hosts.containsKey(host)) { throw new NotFoundException("Host " + host + " was not found"); } hosts.get(host).setMaintenanceMode(maintenance); if (servicesOnHost != null) { for (ServiceRegistrationInMemoryImpl r : servicesOnHost) { r.setMaintenance(maintenance); } } }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#getMaxLoadOnNode(java.lang.String) */ @Override public NodeLoad getMaxLoadOnNode(String host) throws ServiceRegistryException, NotFoundException { Query query = null; EntityManager em = null; try { em = emf.createEntityManager(); query = em.createNamedQuery("HostRegistration.getMaxLoadByHostName"); query.setParameter("host", host); return new NodeLoad(host, ((Number) query.getSingleResult()).floatValue()); } catch (NoResultException e) { throw new NotFoundException(e); } catch (Exception e) { throw new ServiceRegistryException(e); } finally { if (em != null) em.close(); } }
/** * Returns the md5 hash value for the given mediapackage element. * * @throws NotFoundException * if the media package element does not exist */ String getMediaPackageElementDigest(String mediaPackageID, String mediaPackageElementID) throws IOException, IllegalStateException, NotFoundException { File f = getFile(mediaPackageID, mediaPackageElementID); if (f == null) throw new NotFoundException(mediaPackageID + "/" + mediaPackageElementID); return getFileDigest(f); }
/** * {@inheritDoc} * * @see org.opencastproject.workflow.api.WorkflowService#remove(long) */ @Override public void remove(long workflowInstanceId) throws WorkflowDatabaseException, WorkflowParsingException, NotFoundException, UnauthorizedException { HttpDelete delete = new HttpDelete("/remove/" + Long.toString(workflowInstanceId)); HttpResponse response = getResponse(delete, SC_NO_CONTENT, SC_NOT_FOUND); try { if (response != null) { if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) { throw new NotFoundException("Workflow id not found: " + workflowInstanceId); } else { logger.info("Workflow '{}' removed", workflowInstanceId); return; } } } finally { closeConnection(response); } throw new WorkflowDatabaseException("Unable to remove workflow instance " + workflowInstanceId); }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#sanitize(java.lang.String, java.lang.String) */ @Override public void sanitize(String serviceType, String host) throws NotFoundException { EntityManager em = null; try { em = emf.createEntityManager(); ServiceRegistrationJpaImpl service = getServiceRegistration(em, serviceType, host); if (service == null) throw new NotFoundException(""); logger.info("State reset to NORMAL for service {} on host {} through santize method", service.getServiceType(), service.getHost()); service.setServiceState(NORMAL); updateServiceState(em, service); } finally { if (em != null) em.close(); } }
@Override public void deleteFromCollection(String collectionId, String fileName, boolean removeCollection) throws NotFoundException, IOException { // local delete final File f = workspaceFile(WorkingFileRepository.COLLECTION_PATH_PREFIX, collectionId, PathSupport.toSafeName(fileName)); FileUtils.deleteQuietly(f); if (removeCollection) { FileSupport.delete(f.getParentFile()); } // delete in WFR try { wfr.deleteFromCollection(collectionId, fileName, removeCollection); } catch (IllegalArgumentException e) { throw new NotFoundException(e); } // wait for WFR waitForResource(wfr.getCollectionURI(collectionId, fileName), SC_NOT_FOUND, "File %s does not disappear in WFR"); }
@Override public Incident getIncident(long id) throws IncidentServiceException, NotFoundException { for (IncidentDto dto : getPenv().tx(Queries.find(IncidentDto.class, id))) { final Job job = findJob(dto.getJobId()); if (job != null) { return toIncident(job, dto); } } throw new NotFoundException(); }