use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class QueueStatusResource method get.
/**
* This method will list all the child resources for the given resource type
*
* @param type child resource type
* @return list of child resources of the given child resource type
*/
@Override
public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
List<ExperimentCatResource> result = new ArrayList<>();
EntityManager em = null;
try {
String query = "SELECT q from QueueStatus q WHERE q.time IN (SELECT MAX(q2.time) FROM QueueStatus q2 GROUP BY q2.hostName, q2.queueName)";
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
Query q = em.createQuery(query);
List resultList = q.getResultList();
for (Object o : resultList) {
QueueStatus queueStatus = (QueueStatus) o;
QueueStatusResource queueStatusResource = new QueueStatusResource();
queueStatusResource.setHostName(queueStatus.getHostName());
queueStatusResource.setQueueName(queueStatus.getQueueName());
queueStatusResource.setTime(queueStatus.getTime());
queueStatusResource.setQueueUp(queueStatus.getQueueUp());
queueStatusResource.setQueuedJobs(queueStatus.getQueuedJobs());
queueStatusResource.setRunningJobs(queueStatus.getRunningJobs());
result.add(queueStatusResource);
}
em.getTransaction().commit();
em.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
return result;
}
use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class TaskResource method save.
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
Task task;
Task existingTask = em.find(Task.class, taskId);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if (existingTask == null) {
task = new Task();
} else {
task = existingTask;
}
task.setTaskId(taskId);
task.setTaskType(taskType);
task.setParentProcessId(parentProcessId);
task.setCreationTime(creationTime);
task.setLastUpdateTime(lastUpdateTime);
task.setTaskDetail(taskDetail);
task.setSetSubTaskModel(subTaskModel);
if (existingTask == null) {
em.persist(task);
} else {
em.merge(task);
}
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class TaskResource method remove.
public void remove(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
Query q;
QueryGenerator generator;
switch(type) {
case TASK_STATUS:
generator = new QueryGenerator(TASK_STATUS);
generator.setParameter(TaskStatusConstants.STATUS_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case TASK_ERROR:
generator = new QueryGenerator(TASK_ERROR);
generator.setParameter(TaskErrorConstants.ERROR_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case JOB:
generator = new QueryGenerator(JOB);
generator.setParameter(JobConstants.JOB_ID, name);
generator.setParameter(JobConstants.TASK_ID, taskId);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
default:
logger.error("Unsupported resource type for job details resource.", new IllegalArgumentException());
break;
}
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class TaskResource method get.
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch(type) {
case TASK_STATUS:
generator = new QueryGenerator(TASK_STATUS);
generator.setParameter(TaskStatusConstants.STATUS_ID, name);
q = generator.selectQuery(em);
TaskStatus status = (TaskStatus) q.getSingleResult();
TaskStatusResource statusResource = (TaskStatusResource) Utils.getResource(ResourceType.TASK_STATUS, status);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return statusResource;
case TASK_ERROR:
generator = new QueryGenerator(TASK_ERROR);
generator.setParameter(TaskErrorConstants.ERROR_ID, name);
q = generator.selectQuery(em);
TaskError error = (TaskError) q.getSingleResult();
TaskErrorResource errorResource = (TaskErrorResource) Utils.getResource(ResourceType.TASK_ERROR, error);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return errorResource;
case JOB:
generator = new QueryGenerator(JOB);
generator.setParameter(JobConstants.JOB_ID, name);
generator.setParameter(JobConstants.TASK_ID, taskId);
q = generator.selectQuery(em);
Job job = (Job) q.getSingleResult();
JobResource jobResource = (JobResource) Utils.getResource(ResourceType.JOB, job);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return jobResource;
default:
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported resource type for Task resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for Task resource.");
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class UserResource method save.
/**
* save user to the database
*/
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
UserPK userPK = new UserPK();
userPK.setGatewayId(gatewayId);
userPK.setUserName(userName);
Users existingUser = em.find(Users.class, userPK);
Gateway gateway = em.find(Gateway.class, gatewayId);
em.close();
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
Users user = new Users();
user.setAiravataInternalUserId(userName + "@" + gatewayId);
user.setUserName(userName);
user.setGatewayId(gateway.getGatewayId());
user.setGateway(gateway);
if (password != null && !password.equals("")) {
try {
user.setPassword(SecurityUtil.digestString(password, ServerSettings.getSetting("default.registry.password.hash.method")));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Error hashing default admin password. Invalid hash algorithm.", e);
} catch (ApplicationSettingsException e) {
throw new RuntimeException("Error reading hash algorithm from configurations", e);
}
}
if (existingUser != null) {
if (password != null && !password.equals("")) {
try {
existingUser.setPassword(SecurityUtil.digestString(password, ServerSettings.getSetting("default.registry.password.hash.method")));
existingUser.setGatewayId(gateway.getGatewayId());
existingUser.setGateway(gateway);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Error hashing default admin password. Invalid hash algorithm.", e);
} catch (ApplicationSettingsException e) {
throw new RuntimeException("Error reading hash algorithm from configurations", e);
}
}
user = em.merge(existingUser);
} else {
em.persist(user);
}
em.getTransaction().commit();
em.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
Aggregations