use of org.opencastproject.serviceregistry.impl.jpa.HostRegistrationJpaImpl in project opencast by opencast.
the class ServiceRegistryJpaImpl method enableHost.
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#enableHost(String)
*/
@Override
public void enableHost(String host) throws ServiceRegistryException, NotFoundException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
// Find the existing registrations for this host and if it exists, update it
HostRegistrationJpaImpl hostRegistration = fetchHostRegistration(em, host);
if (hostRegistration == null) {
throw new NotFoundException("Host '" + host + "' is currently not registered, so it can not be enabled");
} else {
hostRegistration.setActive(true);
em.merge(hostRegistration);
}
logger.info("Enabling {}", host);
tx.commit();
tx.begin();
for (ServiceRegistration serviceRegistration : getServiceRegistrationsByHost(host)) {
ServiceRegistrationJpaImpl registration = (ServiceRegistrationJpaImpl) serviceRegistration;
registration.setActive(true);
em.merge(registration);
servicesStatistics.updateService(registration);
}
tx.commit();
hostsStatistics.updateHost(hostRegistration);
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
if (tx != null && tx.isActive()) {
tx.rollback();
}
throw new ServiceRegistryException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.serviceregistry.impl.jpa.HostRegistrationJpaImpl in project opencast by opencast.
the class ServiceRegistryJpaImpl method setMaintenanceStatus.
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#setMaintenanceStatus(java.lang.String, boolean)
*/
@Override
public void setMaintenanceStatus(String baseUrl, boolean maintenance) throws NotFoundException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
HostRegistrationJpaImpl reg = fetchHostRegistration(em, baseUrl);
if (reg == null) {
throw new NotFoundException("Can not set maintenance mode on a host that has not been registered");
}
reg.setMaintenanceMode(maintenance);
em.merge(reg);
tx.commit();
hostsStatistics.updateHost(reg);
} catch (RollbackException e) {
if (tx != null && tx.isActive()) {
tx.rollback();
}
throw e;
} finally {
if (em != null)
em.close();
}
}
Aggregations