/** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.airavata.registry.core.experiment.catalog.resources; import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; import org.apache.airavata.registry.core.experiment.catalog.ResourceType; import org.apache.airavata.registry.core.experiment.catalog.model.TaskError; import org.apache.airavata.registry.core.experiment.catalog.model.TaskErrorPK; import org.apache.airavata.registry.cpi.RegistryException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.persistence.EntityManager; import java.sql.Timestamp; import java.util.List; public class TaskErrorResource extends AbstractExpCatResource { private static final Logger logger = LoggerFactory.getLogger(TaskErrorResource.class); private String errorId; private String taskId; private Timestamp creationTime; private String actualErrorMessage; private String userFriendlyMessage; private boolean transientOrPersistent; private String rootCauseErrorIdList; public String getErrorId() { return errorId; } public void setErrorId(String errorId) { this.errorId = errorId; } public String getTaskId() { return taskId; } public void setTaskId(String taskId) { this.taskId = taskId; } public Timestamp getCreationTime() { return creationTime; } public void setCreationTime(Timestamp creationTime) { this.creationTime = creationTime; } public String getActualErrorMessage() { return actualErrorMessage; } public void setActualErrorMessage(String actualErrorMessage) { this.actualErrorMessage = actualErrorMessage; } public String getUserFriendlyMessage() { return userFriendlyMessage; } public void setUserFriendlyMessage(String userFriendlyMessage) { this.userFriendlyMessage = userFriendlyMessage; } public boolean getTransientOrPersistent() { return transientOrPersistent; } public void setTransientOrPersistent(boolean transientOrPersistent) { this.transientOrPersistent = transientOrPersistent; } public String getRootCauseErrorIdList() { return rootCauseErrorIdList; } public void setRootCauseErrorIdList(String rootCauseErrorIdList) { this.rootCauseErrorIdList = rootCauseErrorIdList; } public ExperimentCatResource create(ResourceType type) throws RegistryException { logger.error("Unsupported resource type for task error data resource.", new UnsupportedOperationException()); throw new UnsupportedOperationException(); } public void remove(ResourceType type, Object name) throws RegistryException { logger.error("Unsupported resource type for task error data resource.", new UnsupportedOperationException()); throw new UnsupportedOperationException(); } public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ logger.error("Unsupported resource type for task error data resource.", new UnsupportedOperationException()); throw new UnsupportedOperationException(); } public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ logger.error("Unsupported resource type for task error data resource.", new UnsupportedOperationException()); throw new UnsupportedOperationException(); } public void save() throws RegistryException{ EntityManager em = null; try { em = ExpCatResourceUtils.getEntityManager(); TaskError taskError; if(taskId == null || errorId == null){ throw new RegistryException("Does not have the task id or error id"); } TaskErrorPK taskErrorPK = new TaskErrorPK(); taskErrorPK.setTaskId(taskId); taskErrorPK.setErrorId(errorId); TaskError existingTaskError = em.find(TaskError.class, taskErrorPK); if (em.isOpen()) { if (em.getTransaction().isActive()){ em.getTransaction().rollback(); } em.close(); } em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); if(existingTaskError == null){ taskError = new TaskError(); }else { taskError = existingTaskError; } taskError.setTaskId(taskId); taskError.setErrorId(errorId); taskError.setActualErrorMessage(actualErrorMessage); taskError.setUserFriendlyMessage(userFriendlyMessage); taskError.setRootCauseErrorIdList(rootCauseErrorIdList); taskError.setTransientOrPersistent(transientOrPersistent); if (existingTaskError == null){ em.persist(taskError); }else { em.merge(taskError); } 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(); } } } }