Search in sources :

Example 86 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class ServiceRegistryInMemoryImpl method registerService.

/**
 * {@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;
}
Also used : NotFoundException(org.opencastproject.util.NotFoundException)

Example 87 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class ServiceRegistryInMemoryImpl method dispatchJob.

/**
 * Dispatches the job to the least loaded service or throws a <code>ServiceUnavailableException</code> if there is no
 * such service.
 *
 * @param job
 *          the job to dispatch
 * @return whether the job was dispatched
 * @throws ServiceUnavailableException
 *           if no service is available to dispatch the job
 * @throws ServiceRegistryException
 *           if the service registrations are unavailable or dispatching of the job fails
 */
protected boolean dispatchJob(Job job) throws ServiceUnavailableException, ServiceRegistryException, UndispatchableJobException {
    List<ServiceRegistration> registrations = getServiceRegistrationsByLoad(job.getJobType());
    if (registrations.size() == 0)
        throw new ServiceUnavailableException("No service is available to handle jobs of type '" + job.getJobType() + "'");
    job.setStatus(Status.DISPATCHING);
    try {
        job = updateJob(job);
    } catch (NotFoundException e) {
        throw new ServiceRegistryException("Job not found!", e);
    }
    for (ServiceRegistration registration : registrations) {
        if (registration.isJobProducer() && !registration.isInMaintenanceMode()) {
            ServiceRegistrationInMemoryImpl inMemoryRegistration = (ServiceRegistrationInMemoryImpl) registration;
            JobProducer service = inMemoryRegistration.getService();
            // Add the job to the list of jobs so that it gets counted in the load.
            // This is the same way that the JPA impl does it
            Set<Job> jobs = jobHosts.get(inMemoryRegistration);
            if (jobs == null) {
                jobs = new LinkedHashSet<Job>();
            }
            jobs.add(job);
            jobHosts.put(inMemoryRegistration, jobs);
            if (!service.isReadyToAcceptJobs(job.getOperation())) {
                jobs.remove(job);
                jobHosts.put(inMemoryRegistration, jobs);
                continue;
            }
            if (!service.isReadyToAccept(job)) {
                jobs.remove(job);
                jobHosts.put(inMemoryRegistration, jobs);
                continue;
            }
            try {
                job = updateJob(job);
            } catch (NotFoundException e) {
                jobs.remove(job);
                jobHosts.put(inMemoryRegistration, jobs);
                throw new ServiceRegistryException("Job not found!", e);
            }
            service.acceptJob(job);
            return true;
        } else if (!registration.isJobProducer()) {
            logger.warn("This implementation of the service registry doesn't support dispatching to remote services");
        // TODO: Add remote dispatching
        } else {
            logger.warn("Service " + registration + " is in maintenance mode");
        }
    }
    return false;
}
Also used : JobProducer(org.opencastproject.job.api.JobProducer) NotFoundException(org.opencastproject.util.NotFoundException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job)

Example 88 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class DownloadDistributionServiceImpl method distributeElement.

/**
 * Distribute a Mediapackage element to the download distribution service.
 *
 * @param channelId
 *   #          The id of the publication channel to be distributed to.
 * @param mediapackage
 *          The media package that contains the element to be distributed.
 * @param element
 *          The the element that should be distributed contained within the media package.
 * @param checkAvailability
 *          Check the availability of the distributed element via http.
 * @param preserveReference
 *           Copy existing Track-Reference to the new distributed Track
 * @return A reference to the MediaPackageElement that has been distributed.
 * @throws DistributionException
 *           Thrown if the parent directory of the MediaPackageElement cannot be created, if the MediaPackageElement
 *           cannot be copied or another unexpected exception occurs.
 */
public MediaPackageElement distributeElement(String channelId, MediaPackage mediapackage, MediaPackageElement element, boolean checkAvailability, boolean preserveReference) throws DistributionException {
    final String mediapackageId = mediapackage.getIdentifier().compact();
    final String elementId = element.getIdentifier();
    try {
        File source;
        try {
            source = workspace.get(element.getURI());
        } catch (NotFoundException e) {
            throw new DistributionException("Unable to find " + element.getURI() + " in the workspace", e);
        } catch (IOException e) {
            throw new DistributionException("Error loading " + element.getURI() + " from the workspace", e);
        }
        // Try to find a duplicated element source
        try {
            source = findDuplicatedElementSource(source, mediapackageId);
        } catch (IOException e) {
            logger.warn("Unable to find duplicated source {}: {}", source, ExceptionUtils.getMessage(e));
        }
        File destination = getDistributionFile(channelId, mediapackage, element);
        if (!destination.equals(source)) {
            // Put the file in place if sourcesfile differs destinationfile
            try {
                FileUtils.forceMkdir(destination.getParentFile());
            } catch (IOException e) {
                throw new DistributionException("Unable to create " + destination.getParentFile(), e);
            }
            logger.debug("Distributing element {} of media package {} to publication channel {} ({})", elementId, mediapackageId, channelId, destination);
            try {
                FileSupport.link(source, destination, true);
            } catch (IOException e) {
                throw new DistributionException(format("Unable to copy %s to %s", source, destination), e);
            }
        }
        // Create a media package element representation of the distributed file
        MediaPackageElement distributedElement = (MediaPackageElement) element.clone();
        try {
            distributedElement.setURI(getDistributionUri(channelId, mediapackageId, element));
            if (preserveReference) {
                distributedElement.setReference(element.getReference());
            }
        } catch (URISyntaxException e) {
            throw new DistributionException("Distributed element produces an invalid URI", e);
        }
        logger.debug("Finished distributing element {} of media package {} to publication channel {}", elementId, mediapackageId, channelId);
        final URI uri = distributedElement.getURI();
        if (checkAvailability) {
            logger.debug("Checking availability of distributed artifact {} at {}", distributedElement, uri);
            waitForResource(trustedHttpClient, uri, HttpServletResponse.SC_OK, TIMEOUT, INTERVAL).fold(Misc.<Exception, Void>chuck(), new Effect.X<Integer>() {

                @Override
                public void xrun(Integer status) throws Exception {
                    if (ne(status, HttpServletResponse.SC_OK)) {
                        logger.warn("Attempt to access distributed file {} returned code {}", uri, status);
                        throw new DistributionException("Unable to load distributed file " + uri.toString());
                    }
                }
            });
        }
        return distributedElement;
    } catch (Exception e) {
        logger.warn("Error distributing " + element, e);
        if (e instanceof DistributionException) {
            throw (DistributionException) e;
        } else {
            throw new DistributionException(e);
        }
    }
}
Also used : NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) DistributionException(org.opencastproject.distribution.api.DistributionException) Effect(org.opencastproject.util.data.Effect) File(java.io.File)

Example 89 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class OrganizationPersistenceTest method testDeleting.

@Test
public void testDeleting() throws Exception {
    Map<String, String> orgProperties = new HashMap<String, String>();
    orgProperties.put("test", "one");
    JpaOrganization org = new JpaOrganization("newOrg", "test organization", "test.org", 8080, "ROLE_TEST_ADMIN", "ROLE_TEST_ANONYMOUS", orgProperties);
    organizationDatabase.storeOrganization(org);
    Assert.assertTrue(organizationDatabase.containsOrganization("newOrg"));
    try {
        organizationDatabase.getOrganization("newOrg");
    } catch (NotFoundException e) {
        Assert.fail("Organization not found");
    }
    organizationDatabase.deleteOrganization("newOrg");
    Assert.assertFalse(organizationDatabase.containsOrganization("newOrg"));
    try {
        organizationDatabase.getOrganization("newOrg");
        Assert.fail("Organization found");
    } catch (NotFoundException e) {
        Assert.assertNotNull(e);
    }
}
Also used : JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) HashMap(java.util.HashMap) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Example 90 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class OrganizationPersistenceTest method testAdding.

@Test
public void testAdding() throws Exception {
    Map<String, String> orgProperties = new HashMap<String, String>();
    orgProperties.put("test", "one");
    JpaOrganization org = new JpaOrganization("newOrg", "test organization", "test.org", 8080, "ROLE_TEST_ADMIN", "ROLE_TEST_ANONYMOUS", orgProperties);
    organizationDatabase.storeOrganization(org);
    Assert.assertTrue(organizationDatabase.containsOrganization("newOrg"));
    Organization orgById = organizationDatabase.getOrganization("newOrg");
    try {
        organizationDatabase.getOrganizationByHost("test.org", 8081);
        Assert.fail();
    } catch (NotFoundException e) {
        Assert.assertNotNull(e);
    }
    Organization orgByHost = organizationDatabase.getOrganizationByHost("test.org", 8080);
    Assert.assertEquals(orgById, orgByHost);
    Assert.assertEquals("newOrg", orgById.getId());
    Assert.assertEquals("test organization", orgById.getName());
    Assert.assertEquals("ROLE_TEST_ADMIN", orgById.getAdminRole());
    Assert.assertEquals("ROLE_TEST_ANONYMOUS", orgById.getAnonymousRole());
    Map<String, Integer> servers = orgById.getServers();
    Assert.assertEquals(1, servers.size());
    Assert.assertTrue(servers.containsKey("test.org"));
    Assert.assertTrue(servers.containsValue(8080));
    Map<String, String> properties = orgById.getProperties();
    Assert.assertEquals(1, properties.size());
    Assert.assertTrue(properties.containsKey("test"));
    Assert.assertTrue(properties.containsValue("one"));
}
Also used : DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Organization(org.opencastproject.security.api.Organization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) HashMap(java.util.HashMap) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (org.opencastproject.util.NotFoundException)382 IOException (java.io.IOException)137 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)130 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)79 MediaPackage (org.opencastproject.mediapackage.MediaPackage)69 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)67 EntityManager (javax.persistence.EntityManager)55 SeriesException (org.opencastproject.series.api.SeriesException)53 Path (javax.ws.rs.Path)52 WebApplicationException (javax.ws.rs.WebApplicationException)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)51 ConfigurationException (org.osgi.service.cm.ConfigurationException)51 URI (java.net.URI)50 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)50 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)49 Date (java.util.Date)48 Test (org.junit.Test)47 File (java.io.File)46 HttpResponse (org.apache.http.HttpResponse)46 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)46