use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.
the class SharingRegistryServer method start.
@Override
public void start() throws Exception {
try {
setStatus(IServer.ServerStatus.STARTING);
final int serverPort = Integer.parseInt(ServerSettings.getSetting(SHARING_REG_SERVER_PORT));
final String serverHost = ServerSettings.getSetting(SHARING_REG_SERVER_HOST);
SharingRegistryService.Processor processor = new SharingRegistryService.Processor(new SharingRegistryServerHandler());
TServerTransport serverTransport;
if (serverHost == null) {
serverTransport = new TServerSocket(serverPort);
} else {
InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
serverTransport = new TServerSocket(inetSocketAddress);
}
TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
options.minWorkerThreads = 30;
server = new TThreadPoolServer(options.processor(processor));
new Thread() {
public void run() {
server.serve();
setStatus(IServer.ServerStatus.STOPPED);
logger.info("Sharing Registry Server Stopped.");
}
}.start();
new Thread() {
public void run() {
while (!server.isServing()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
break;
}
}
if (server.isServing()) {
try {
logger.info("Register sharing service with DB Event publishers");
SharingServiceDBEventMessagingFactory.registerSharingServiceWithPublishers(Constants.PUBLISHERS);
logger.info("Start sharing service DB Event subscriber");
SharingServiceDBEventMessagingFactory.getDBEventSubscriber();
} catch (AiravataException | SharingRegistryException e) {
logger.error("Error starting sharing service. Error setting up DB event services.");
server.stop();
}
setStatus(IServer.ServerStatus.STARTED);
logger.info("Starting Sharing Registry Server on Port " + serverPort);
logger.info("Listening to Sharing Registry server clients ....");
}
}
}.start();
} catch (TTransportException e) {
setStatus(IServer.ServerStatus.FAILED);
throw new Exception("Error while starting the Sharing Registry service", e);
}
}
use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.
the class WorkflowEngineImpl method launchExperiment.
@Override
public void launchExperiment(String experimentId, String token) throws WorkflowEngineException {
try {
ExperimentCatalog experimentCatalog = RegistryFactory.getDefaultExpCatalog();
Experiment experiment = (Experiment) experimentCatalog.get(ExperimentCatalogModelType.EXPERIMENT, experimentId);
WorkflowCatalog workflowCatalog = WorkflowCatalogFactory.getWorkflowCatalog();
WorkflowInterpreterConfiguration config = new WorkflowInterpreterConfiguration(new Workflow(workflowCatalog.getWorkflow(experiment.getApplicationId()).getGraph()));
final WorkflowInterpreter workflowInterpreter = new WorkflowInterpreter(experiment, token, config, getOrchestratorClient(), rabbitMQPublisher);
new Thread() {
public void run() {
try {
workflowInterpreter.scheduleDynamically();
} catch (WorkflowException e) {
logger.error(e.getMessage(), e);
} catch (RegistryException e) {
logger.error(e.getMessage(), e);
} catch (AiravataException e) {
logger.error(e.getMessage(), e);
}
}
}.start();
} catch (Exception e) {
logger.error("Error while retrieving the experiment", e);
WorkflowEngineException exception = new WorkflowEngineException("Error while launching the workflow experiment. More info : " + e.getMessage());
throw exception;
}
}
use of org.apache.airavata.common.exception.AiravataException 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.AiravataException in project airavata by apache.
the class BrowserLauncher method openURL.
/**
* Opens a specified URL with the browser.
*
* @param url
* The specified URL.
* @throws AiravataException
*/
public static void openURL(String url) throws AiravataException {
logger.debug("Enter:" + url);
String osName = System.getProperty("os.name");
try {
if (osName.startsWith("Mac OS")) {
Class macUtils = Class.forName("com.apple.mrj.MRJFileUtils");
Method openURL = macUtils.getDeclaredMethod("openURL", new Class[] { String.class });
openURL.invoke(null, new Object[] { url });
} else if (osName.startsWith("Windows"))
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
else {
// assume Unix or Linux
String[] browsers = { "firefox", "mozilla", "netscape", "opera", "konqueror" };
String browser = null;
for (int count = 0; count < browsers.length && browser == null; count++) if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)
browser = browsers[count];
if (browser == null) {
throw new AiravataException("Could not find web browser.");
} else {
Runtime.getRuntime().exec(new String[] { browser, url });
}
}
} catch (ClassNotFoundException e) {
throw new AiravataException(ERROR_MESSAGE, e);
} catch (NoSuchMethodException e) {
throw new AiravataException(ERROR_MESSAGE, e);
} catch (IllegalAccessException e) {
throw new AiravataException(ERROR_MESSAGE, e);
} catch (InvocationTargetException e) {
throw new AiravataException(ERROR_MESSAGE, e);
} catch (IOException e) {
throw new AiravataException(ERROR_MESSAGE, e);
} catch (InterruptedException e) {
throw new AiravataException(ERROR_MESSAGE, e);
} catch (RuntimeException e) {
throw new AiravataException(ERROR_MESSAGE, e);
}
}
use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.
the class EmailBasedMonitor method processMessages.
private void processMessages(Message[] searchMessages) throws MessagingException {
List<Message> processedMessages = new ArrayList<>();
List<Message> unreadMessages = new ArrayList<>();
for (Message message : searchMessages) {
try {
JobStatusResult jobStatusResult = parse(message);
TaskContext taskContext = null;
if (jobStatusResult.getJobId() != null) {
taskContext = jobMonitorMap.get(jobStatusResult.getJobId());
} else {
log.info("Returned null for job id, message subject--> {}", message.getSubject());
}
if (taskContext == null) {
if (jobStatusResult.getJobName() != null) {
taskContext = jobMonitorMap.get(jobStatusResult.getJobName());
} else {
log.info("Returned null for job name, message subject --> {}", message.getSubject());
}
}
if (taskContext != null) {
process(jobStatusResult, taskContext);
processedMessages.add(message);
} else if (!jobStatusResult.isAuthoritative() && (new Date()).getTime() - message.getSentDate().getTime() > 1000 * 60 * 5) {
// marking old custom Airavata emails as read
processedMessages.add(message);
log.info("Marking old Airavata custom emails as read, message subject --> {}", message.getSubject());
} else {
// we can get JobExecutionContext null in multiple Gfac instances environment,
// where this job is not submitted by this Gfac instance hence we ignore this message.
unreadMessages.add(message);
// log.info("JobExecutionContext is not found for job Id " + jobStatusResult.getJobId());
}
} catch (AiravataException e) {
log.error("[EJM]: Error parsing email message =====================================>", e);
try {
writeEnvelopeOnError(message);
} catch (MessagingException e1) {
log.error("[EJM]: Error printing envelop of the email");
}
unreadMessages.add(message);
} catch (MessagingException e) {
log.error("[EJM]: Error while retrieving sender address from message : " + message.toString());
unreadMessages.add(message);
}
}
if (!processedMessages.isEmpty()) {
Message[] seenMessages = new Message[processedMessages.size()];
processedMessages.toArray(seenMessages);
try {
emailFolder.setFlags(seenMessages, new Flags(Flags.Flag.SEEN), true);
} catch (MessagingException e) {
if (!store.isConnected()) {
store.connect();
emailFolder.setFlags(seenMessages, new Flags(Flags.Flag.SEEN), true);
}
}
}
if (!unreadMessages.isEmpty()) {
Message[] unseenMessages = new Message[unreadMessages.size()];
unreadMessages.toArray(unseenMessages);
try {
emailFolder.setFlags(unseenMessages, new Flags(Flags.Flag.SEEN), false);
} catch (MessagingException e) {
if (!store.isConnected()) {
store.connect();
emailFolder.setFlags(unseenMessages, new Flags(Flags.Flag.SEEN), false);
// anyway we need to push this update.
flushUnseenMessages = unseenMessages;
} else {
// anyway we need to push this update.
flushUnseenMessages = unseenMessages;
}
}
}
}
Aggregations