use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class RegistryServiceDBEventHandler method onMessage.
@Override
public void onMessage(MessageContext messageContext) {
logger.info("RegistryServiceDBEventHandler | Received a new message!");
try {
// construct dbeventmessage thrift datamodel
byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent());
DBEventMessage dbEventMessage = new DBEventMessage();
ThriftUtils.createThriftFromBytes(bytes, dbEventMessage);
logger.info("RegistryService received db-event-message from publisher: " + dbEventMessage.getPublisherService());
// get publisher context
DBEventPublisherContext publisherContext = dbEventMessage.getMessageContext().getPublisher().getPublisherContext();
logger.info("RegistryService, Replicated Entity: " + publisherContext.getEntityType());
// this try-block is mainly for catching DuplicateEntryException
try {
// check type of entity-type
switch(publisherContext.getEntityType()) {
// Gateway related operations
case TENANT:
{
// construct gateway datamodel from message
Gateway gateway = new Gateway();
ThriftUtils.createThriftFromBytes(publisherContext.getEntityDataModel(), gateway);
// call service-methods based on CRUD type
switch(publisherContext.getCrudType()) {
case CREATE:
{
logger.info("Replicating addGateway in Registry.");
registryClient.addGateway(gateway);
logger.info("addGateway Replication Success!");
break;
}
case UPDATE:
{
logger.info("Replicating updateGateway in Registry.");
if (!registryClient.isGatewayExist(gateway.getGatewayId())) {
logger.info("Gateway doesn't exist so adding instead of updating.");
registryClient.addGateway(gateway);
} else {
registryClient.updateGateway(gateway.getGatewayId(), gateway);
}
logger.info("updateGateway Replication Success!");
break;
}
case DELETE:
{
logger.info("Replicating deleteGateway in Registry.");
registryClient.deleteGateway(gateway.getGatewayId());
logger.info("deleteGateway Replication Success!");
break;
}
}
// break entity: gateway
break;
}
// UserProfile related operations
case USER_PROFILE:
{
// construct userprofile datamodel from message
UserProfile userProfile = new UserProfile();
ThriftUtils.createThriftFromBytes(publisherContext.getEntityDataModel(), userProfile);
// call service-methods based on CRUD type
switch(publisherContext.getCrudType()) {
case CREATE:
{
logger.info("Replicating addUser in Registry.");
registryClient.addUser(userProfile);
logger.info("addUser Replication Success!");
break;
}
case UPDATE:
{
logger.info("Replicating updateGateway in Registry.");
// TODO: find appropriate method
break;
}
case DELETE:
{
logger.info("Replicating deleteGateway in Registry.");
// TODO: find appropriate method
break;
}
}
// break entity: userprofile
break;
}
// no handler for entity
default:
{
logger.error("Handler not defined for Entity: " + publisherContext.getEntityType());
}
}
} catch (DuplicateEntryException ex) {
// log this exception and proceed (do nothing)
// this exception is thrown mostly when messages are re-consumed, hence ignore
logger.warn("DuplicateEntryException while consuming db-event message, ex: " + ex.getMessage(), ex);
}
// send ack for received message
logger.info("RegistryServiceDBEventHandler | Sending ack. Message Delivery Tag: " + messageContext.getDeliveryTag());
RegistryServiceDBEventMessagingFactory.getDBEventSubscriber().sendAck(messageContext.getDeliveryTag());
} catch (TException ex) {
logger.error("Error processing message: " + ex, ex);
} catch (ApplicationSettingsException ex) {
logger.error("Error fetching application settings: " + ex, ex);
} catch (AiravataException ex) {
logger.error("Error sending ack. Message Delivery Tag: " + messageContext.getDeliveryTag(), ex);
}
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class ExperimentCatalogInitUtil method initializeDB.
public static void initializeDB() {
System.setProperty("registry.initialize.state", "0");
try {
jdbcDriver = ServerSettings.getSetting(REGISTRY_JDBC_DRIVER);
jdbcURl = ServerSettings.getSetting(REGISTRY_JDBC_URL);
jdbcUser = ServerSettings.getSetting(REGISTRY_JDBC_USER);
jdbcPassword = ServerSettings.getSetting(REGISTRY_JDBC_PASSWORD);
jdbcURl = jdbcURl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
} catch (ApplicationSettingsException e) {
logger.error("Unable to read airavata server properties", e.getMessage());
}
if (getDBType(jdbcURl).equals("derby") && isDerbyStartEnabled()) {
startDerbyInServerMode();
}
db = new JdbcStorage(10, 50, jdbcURl, jdbcDriver, true);
Connection conn = null;
try {
conn = db.connect();
if (!DatabaseCreator.isDatabaseStructureCreated(CONFIGURATION_TABLE, conn)) {
DatabaseCreator.createRegistryDatabase("database_scripts/expcatalog", conn);
logger.info("New Database created for Experiment Catalog !!!");
} else {
logger.info("Database already created for Experiment Catalog !!!");
}
try {
GatewayResource gateway;
if (!ExpCatResourceUtils.isGatewayExist(ServerSettings.getDefaultUserGateway())) {
gateway = (GatewayResource) ExpCatResourceUtils.createGateway(ServerSettings.getDefaultUserGateway());
gateway.setGatewayApprovalStatus(GatewayApprovalStatus.APPROVED.toString());
gateway.save();
} else {
gateway = (GatewayResource) ExpCatResourceUtils.getGateway(ServerSettings.getDefaultUserGateway());
}
UserResource user;
if (!ExpCatResourceUtils.isUserExist(ServerSettings.getDefaultUser(), ServerSettings.getDefaultUserGateway())) {
user = ExpCatResourceUtils.createUser(ServerSettings.getDefaultUser(), ServerSettings.getDefaultUserPassword(), ServerSettings.getDefaultUserGateway());
user.save();
} else {
user = (UserResource) ExpCatResourceUtils.getUser(ServerSettings.getDefaultUser(), ServerSettings.getDefaultUserGateway());
}
WorkerResource workerResource;
if (!gateway.isExists(ResourceType.GATEWAY_WORKER, ServerSettings.getDefaultUserGateway())) {
workerResource = (WorkerResource) gateway.create(ResourceType.GATEWAY_WORKER);
workerResource.setUser(user.getUserName());
workerResource.save();
} else {
workerResource = (WorkerResource) gateway.get(ResourceType.GATEWAY_WORKER, ServerSettings.getDefaultUser());
}
ProjectResource projectResource;
if (!workerResource.isExists(ResourceType.PROJECT, DEFAULT_PROJECT_NAME)) {
projectResource = workerResource.createProject(DEFAULT_PROJECT_NAME);
projectResource.setName(DEFAULT_PROJECT_NAME);
projectResource.setGatewayId(gateway.getGatewayId());
projectResource.save();
}
} catch (ApplicationSettingsException e) {
logger.error("Unable to read airavata-server properties...", e.getMessage());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RuntimeException("Database failure", e);
} finally {
db.closeConnection(conn);
try {
if (conn != null) {
if (!conn.getAutoCommit()) {
conn.commit();
}
conn.close();
}
} catch (SQLException e) {
logger.error("Error while closing database connection...", e.getMessage(), e);
}
}
System.setProperty("registry.initialize.state", "1");
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class WorkflowInputResource method get.
public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
HashMap<String, String> ids;
if (identifier instanceof Map) {
ids = (HashMap<String, String>) identifier;
} else {
logger.error("Identifier should be a map with the field name and it's value");
throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
}
EntityManager em = null;
try {
em = WorkflowCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_INPUT);
generator.setParameter(WorkflowInputConstants.WF_TEMPLATE_ID, ids.get(WorkflowInputConstants.WF_TEMPLATE_ID));
generator.setParameter(WorkflowInputConstants.INPUT_KEY, ids.get(WorkflowInputConstants.INPUT_KEY));
Query q = generator.selectQuery(em);
WorkflowInput workflowInput = (WorkflowInput) q.getSingleResult();
WorkflowInputResource workflowInputResource = (WorkflowInputResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW_INPUT, workflowInput);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return workflowInputResource;
} catch (ApplicationSettingsException e) {
logger.error(e.getMessage(), e);
throw new WorkflowCatalogException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class WorkflowOutputResource method get.
public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
HashMap<String, String> ids;
if (identifier instanceof Map) {
ids = (HashMap) identifier;
} else {
logger.error("Identifier should be a map with the field name and it's value");
throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
}
EntityManager em = null;
try {
em = WorkflowCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_OUTPUT);
generator.setParameter(WorkflowOutputConstants.WF_TEMPLATE_ID, ids.get(WorkflowOutputConstants.WF_TEMPLATE_ID));
generator.setParameter(WorkflowOutputConstants.OUTPUT_KEY, ids.get(WorkflowOutputConstants.OUTPUT_KEY));
Query q = generator.selectQuery(em);
WorkflowOutput wfOutput = (WorkflowOutput) q.getSingleResult();
WorkflowOutputResource workflowOutputResource = (WorkflowOutputResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW_OUTPUT, wfOutput);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return workflowOutputResource;
} catch (ApplicationSettingsException e) {
logger.error(e.getMessage(), e);
throw new WorkflowCatalogException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class WorkflowResource method get.
@Override
public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
List<WorkflowCatalogResource> workflowResources = new ArrayList<WorkflowCatalogResource>();
EntityManager em = null;
try {
em = WorkflowCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
Query q;
if ((fieldName.equals(WorkflowConstants.TEMPLATE_ID)) || (fieldName.equals(WorkflowConstants.GATEWAY_ID))) {
generator.setParameter(fieldName, value);
q = generator.selectQuery(em);
List<?> results = q.getResultList();
for (Object result : results) {
Workflow workflow = (Workflow) result;
WorkflowResource workflowResource = (WorkflowResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW, workflow);
workflowResources.add(workflowResource);
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for Workflow Resource.");
}
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
} catch (ApplicationSettingsException e) {
logger.error(e.getMessage(), e);
throw new WorkflowCatalogException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
return workflowResources;
}
Aggregations