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); } }
private void suspendWaiterJob() { if (this.waiterJobId.isSome()) { try { final Job waiter = serviceRegistry.getJob(waiterJobId.get()); waiter.setStatus(Job.Status.WAITING); List<Long> blockedForJobs = new LinkedList<Long>(); for (Job j : jobs) { try { if (setBlockerJob(j, waiter)) { blockedForJobs.add(j.getId()); } } catch (OptimisticLockException e) { // Try again, this happens if the job finishes before we get here // If the same exception happens again then we're in a very weird state if (setBlockerJob(j, waiter)) { blockedForJobs.add(j.getId()); } } } waiter.setBlockedJobIds(blockedForJobs); this.serviceRegistry.updateJob(waiter); } catch (ServiceRegistryException e) { logger.warn("Unable to put {} into a waiting state, this may cause a deadlock: {}", waiterJobId, e.getMessage()); } catch (NotFoundException e) { logger.warn("Unable to put {} into a waiting state, job not found by the service registry. This may cause a deadlock: {}", waiterJobId, e.getMessage()); } } else { logger.debug("No waiting job set, unable to put waiting job into waiting state"); } }
private void wakeWaiterJob() { if (this.waiterJobId.isSome()) { try { final Job waiter = serviceRegistry.getJob(waiterJobId.get()); waiter.setStatus(Job.Status.RUNNING); for (Job j : jobs) { Job updatedJob = this.serviceRegistry.getJob(j.getId()); updatedJob.removeBlockingJobId(); // FYI not updating local j in jobs collection this.serviceRegistry.updateJob(updatedJob); } waiter.removeBlockedJobsIds(); this.serviceRegistry.updateJob(waiter); } catch (ServiceRegistryException e) { logger.warn("Unable to put {} into a waiting state, this may cause a deadlock: {}", waiterJobId, e.getMessage()); } catch (NotFoundException e) { logger.warn("Unable to put {} into a waiting state, job not found by the service registry. This may cause a deadlock: {}", waiterJobId, e.getMessage()); } } else { logger.debug("No waiting job set, unable to put waiting job into waiting state"); } }
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 String id) throws NotFoundException { Organization org = cache.get(id); if (org == null) throw new NotFoundException(); return org; }
@Override public Organization getOrganization(final URL url) throws NotFoundException { Organization org = cache.get(url); 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); } } }
throw new NotFoundException("Error acquiring lock for " + file.getAbsolutePath(), 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(); } }
/** * @see org.opencastproject.kernel.security.persistence.OrganizationDatabase#deleteOrganization(java.lang.String) */ @Override public void deleteOrganization(String orgId) throws OrganizationDatabaseException, NotFoundException { EntityManager em = null; EntityTransaction tx = null; try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); JpaOrganization organization = getOrganizationEntity(orgId, em); if (organization == null) throw new NotFoundException("Organization " + orgId + " does not exist"); em.remove(organization); tx.commit(); } catch (NotFoundException e) { throw e; } catch (Exception e) { logger.error("Could not delete organization: {}", e.getMessage()); if (tx.isActive()) { tx.rollback(); } throw new OrganizationDatabaseException(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); }