This is an automated email from the ASF dual-hosted git repository.
yasith pushed a commit to branch feat/single-jvm
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/feat/single-jvm by this push:
new e9541cf27b refactor: simplify IServer interface, fix all
implementations
e9541cf27b is described below
commit e9541cf27b7170d8e8daee4b36420d8c6d75dcca
Author: yasithdev <[email protected]>
AuthorDate: Thu Mar 26 02:32:15 2026 -0500
refactor: simplify IServer interface, fix all implementations
- IServer: remove getVersion(), restart(), configure(); fix STOPING→STOPPING
- MonitoringServer: implement IServer with getName(), getStatus(), lifecycle
- ComputationalResourceMonitoringService: fix null getName()
- DBEventManagerRunner: implement stop() via
DBEventManagerMessagingFactory.close()
- Delete dead OrchestratorServer and ProfileServiceServer
- All implementations now consistently implement the lean interface
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---
.../apache/airavata/api/server/AiravataServer.java | 19 +-
.../org/apache/airavata/common/utils/IServer.java | 37 ++--
.../ComputationalResourceMonitoringService.java | 21 +-
.../db/event/manager/DBEventManagerRunner.java | 28 +--
.../messaging/DBEventManagerMessagingFactory.java | 14 ++
.../metadata/analyzer/DataInterpreterService.java | 17 +-
.../rescheduler/ProcessReschedulingService.java | 17 +-
.../orchestrator/server/OrchestratorServer.java | 237 ---------------------
.../patform/monitoring/MonitoringServer.java | 27 ++-
.../profile/server/ProfileServiceServer.java | 190 -----------------
10 files changed, 75 insertions(+), 532 deletions(-)
diff --git
a/airavata-api/src/main/java/org/apache/airavata/api/server/AiravataServer.java
b/airavata-api/src/main/java/org/apache/airavata/api/server/AiravataServer.java
index 69dbc9cb71..69f3f6c65b 100644
---
a/airavata-api/src/main/java/org/apache/airavata/api/server/AiravataServer.java
+++
b/airavata-api/src/main/java/org/apache/airavata/api/server/AiravataServer.java
@@ -92,7 +92,6 @@ public class AiravataServer implements IServer {
private static final Logger logger =
LoggerFactory.getLogger(AiravataServer.class);
private static final String SERVER_NAME = "Airavata Server";
- private static final String SERVER_VERSION = "1.0";
private ServerStatus status;
private TServer server;
@@ -291,7 +290,7 @@ public class AiravataServer implements IServer {
@Override
public void stop() throws Exception {
if (server != null && server.isServing()) {
- setStatus(ServerStatus.STOPING);
+ setStatus(ServerStatus.STOPPING);
server.stop();
}
for (IServer service : backgroundServices) {
@@ -304,16 +303,7 @@ public class AiravataServer implements IServer {
}
@Override
- public void restart() throws Exception {
- stop();
- start();
- }
-
- @Override
- public void configure() throws Exception {}
-
- @Override
- public ServerStatus getStatus() throws Exception {
+ public ServerStatus getStatus() {
return status;
}
@@ -322,11 +312,6 @@ public class AiravataServer implements IServer {
return SERVER_NAME;
}
- @Override
- public String getVersion() {
- return SERVER_VERSION;
- }
-
private void setStatus(ServerStatus stat) {
status = stat;
status.updateTime();
diff --git
a/airavata-api/src/main/java/org/apache/airavata/common/utils/IServer.java
b/airavata-api/src/main/java/org/apache/airavata/common/utils/IServer.java
index 4663a5e7bf..dfd0cd8701 100644
--- a/airavata-api/src/main/java/org/apache/airavata/common/utils/IServer.java
+++ b/airavata-api/src/main/java/org/apache/airavata/common/utils/IServer.java
@@ -22,38 +22,39 @@ package org.apache.airavata.common.utils;
import java.util.Calendar;
import java.util.Date;
+/**
+ * Common lifecycle interface for all Airavata server components —
+ * both the main Thrift server and background services.
+ */
public interface IServer {
- public enum ServerStatus {
- STOPING,
+
+ enum ServerStatus {
STOPPED,
STARTING,
STARTED,
+ STOPPING,
FAILED;
+ private Date timestamp;
+
public void updateTime() {
- now = Calendar.getInstance().getTime();
+ timestamp = Calendar.getInstance().getTime();
}
- private Date now;
-
public Date getTime() {
- return now;
+ return timestamp;
}
}
- public String getName();
-
- public String getVersion();
-
- public void start() throws Exception;
-
- public void stop() throws Exception;
+ /** Human-readable name for logging and diagnostics. */
+ String getName();
- public void restart() throws Exception;
+ /** Start this component. Implementations should set status to STARTING
then STARTED. */
+ void start() throws Exception;
- public void configure() throws Exception;
+ /** Stop this component. Implementations should set status to STOPPING
then STOPPED. */
+ void stop() throws Exception;
- public ServerStatus getStatus() throws Exception;
- // public void waitForServerToStart() throws Exception;
- // public void waitForServerToStop() throws Exception;
+ /** Current lifecycle status. */
+ ServerStatus getStatus();
}
diff --git
a/airavata-api/src/main/java/org/apache/airavata/compute/resource/monitoring/ComputationalResourceMonitoringService.java
b/airavata-api/src/main/java/org/apache/airavata/compute/resource/monitoring/ComputationalResourceMonitoringService.java
index f1ef8c2586..bcfd3573b0 100644
---
a/airavata-api/src/main/java/org/apache/airavata/compute/resource/monitoring/ComputationalResourceMonitoringService.java
+++
b/airavata-api/src/main/java/org/apache/airavata/compute/resource/monitoring/ComputationalResourceMonitoringService.java
@@ -37,8 +37,7 @@ import org.slf4j.LoggerFactory;
public class ComputationalResourceMonitoringService implements IServer {
private static final Logger logger =
LoggerFactory.getLogger(ComputationalResourceMonitoringService.class);
- private static final String SERVER_NAME = "Airavata Compute Resource
Monitoring Service";
- private static final String SERVER_VERSION = "1.0";
+ private static final String SERVER_NAME = "Computational Resource
Monitoring";
private static ServerStatus status;
private static Scheduler scheduler;
@@ -46,12 +45,7 @@ public class ComputationalResourceMonitoringService
implements IServer {
@Override
public String getName() {
- return null;
- }
-
- @Override
- public String getVersion() {
- return null;
+ return SERVER_NAME;
}
@Override
@@ -110,16 +104,7 @@ public class ComputationalResourceMonitoringService
implements IServer {
}
@Override
- public void restart() throws Exception {
- stop();
- start();
- }
-
- @Override
- public void configure() throws Exception {}
-
- @Override
- public ServerStatus getStatus() throws Exception {
+ public ServerStatus getStatus() {
return status;
}
diff --git
a/airavata-api/src/main/java/org/apache/airavata/db/event/manager/DBEventManagerRunner.java
b/airavata-api/src/main/java/org/apache/airavata/db/event/manager/DBEventManagerRunner.java
index 972c4bf5f1..22d067bdb8 100644
---
a/airavata-api/src/main/java/org/apache/airavata/db/event/manager/DBEventManagerRunner.java
+++
b/airavata-api/src/main/java/org/apache/airavata/db/event/manager/DBEventManagerRunner.java
@@ -33,7 +33,6 @@ public class DBEventManagerRunner implements IServer {
private static final Logger log =
LogManager.getLogger(DBEventManagerRunner.class);
private static final String SERVER_NAME = "DB Event Manager";
- private static final String SERVER_VERSION = "1.0";
private ServerStatus status;
@@ -84,11 +83,6 @@ public class DBEventManagerRunner implements IServer {
return SERVER_NAME;
}
- @Override
- public String getVersion() {
- return SERVER_VERSION;
- }
-
@Override
public void start() throws Exception {
@@ -113,22 +107,18 @@ public class DBEventManagerRunner implements IServer {
@Override
public void stop() throws Exception {
-
- // TODO: implement stopping the DBEventManager
- }
-
- @Override
- public void restart() throws Exception {
-
- stop();
- start();
+ setStatus(ServerStatus.STOPPING);
+ try {
+ DBEventManagerMessagingFactory.close();
+ setStatus(ServerStatus.STOPPED);
+ } catch (Exception e) {
+ log.error("Error stopping DB Event Manager", e);
+ setStatus(ServerStatus.FAILED);
+ }
}
@Override
- public void configure() throws Exception {}
-
- @Override
- public ServerStatus getStatus() throws Exception {
+ public ServerStatus getStatus() {
return status;
}
diff --git
a/airavata-api/src/main/java/org/apache/airavata/db/event/manager/messaging/DBEventManagerMessagingFactory.java
b/airavata-api/src/main/java/org/apache/airavata/db/event/manager/messaging/DBEventManagerMessagingFactory.java
index 8c8a37c279..4ae09faadd 100644
---
a/airavata-api/src/main/java/org/apache/airavata/db/event/manager/messaging/DBEventManagerMessagingFactory.java
+++
b/airavata-api/src/main/java/org/apache/airavata/db/event/manager/messaging/DBEventManagerMessagingFactory.java
@@ -70,4 +70,18 @@ public class DBEventManagerMessagingFactory {
}
return dbEventPublisher;
}
+
+ /**
+ * Reset subscriber and publisher references, releasing them for GC.
+ */
+ public static synchronized void close() {
+ if (dbEventSubscriber != null) {
+ log.info("Releasing DB Event subscriber");
+ dbEventSubscriber = null;
+ }
+ if (dbEventPublisher != null) {
+ log.info("Releasing DB Event publisher");
+ dbEventPublisher = null;
+ }
+ }
}
diff --git
a/airavata-api/src/main/java/org/apache/airavata/metascheduler/metadata/analyzer/DataInterpreterService.java
b/airavata-api/src/main/java/org/apache/airavata/metascheduler/metadata/analyzer/DataInterpreterService.java
index a4198df4fa..0771cdbbab 100644
---
a/airavata-api/src/main/java/org/apache/airavata/metascheduler/metadata/analyzer/DataInterpreterService.java
+++
b/airavata-api/src/main/java/org/apache/airavata/metascheduler/metadata/analyzer/DataInterpreterService.java
@@ -35,7 +35,6 @@ public class DataInterpreterService implements IServer {
private static final Logger logger =
LoggerFactory.getLogger(DataInterpreterService.class);
private static final String SERVER_NAME = "Data Interpreter Service";
- private static final String SERVER_VERSION = "1.0";
private static ServerStatus status;
private static Scheduler scheduler;
@@ -46,11 +45,6 @@ public class DataInterpreterService implements IServer {
return SERVER_NAME;
}
- @Override
- public String getVersion() {
- return SERVER_VERSION;
- }
-
@Override
public void start() throws Exception {
jobTriggerMap.clear();
@@ -94,16 +88,7 @@ public class DataInterpreterService implements IServer {
}
@Override
- public void restart() throws Exception {
- stop();
- start();
- }
-
- @Override
- public void configure() throws Exception {}
-
- @Override
- public ServerStatus getStatus() throws Exception {
+ public ServerStatus getStatus() {
return status;
}
diff --git
a/airavata-api/src/main/java/org/apache/airavata/metascheduler/process/scheduling/engine/rescheduler/ProcessReschedulingService.java
b/airavata-api/src/main/java/org/apache/airavata/metascheduler/process/scheduling/engine/rescheduler/ProcessReschedulingService.java
index ad829bafee..b0dce1a5c2 100644
---
a/airavata-api/src/main/java/org/apache/airavata/metascheduler/process/scheduling/engine/rescheduler/ProcessReschedulingService.java
+++
b/airavata-api/src/main/java/org/apache/airavata/metascheduler/process/scheduling/engine/rescheduler/ProcessReschedulingService.java
@@ -37,7 +37,6 @@ public class ProcessReschedulingService implements IServer {
private static final Logger logger =
LoggerFactory.getLogger(ProcessReschedulingService.class);
private static final String SERVER_NAME = "Airavata Process Rescheduling
Service";
- private static final String SERVER_VERSION = "1.0";
private static ServerStatus status;
private static Scheduler scheduler;
@@ -48,11 +47,6 @@ public class ProcessReschedulingService implements IServer {
return SERVER_NAME;
}
- @Override
- public String getVersion() {
- return SERVER_VERSION;
- }
-
@Override
public void start() throws Exception {
@@ -97,16 +91,7 @@ public class ProcessReschedulingService implements IServer {
}
@Override
- public void restart() throws Exception {
- stop();
- start();
- }
-
- @Override
- public void configure() throws Exception {}
-
- @Override
- public ServerStatus getStatus() throws Exception {
+ public ServerStatus getStatus() {
return status;
}
diff --git
a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServer.java
b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServer.java
deleted file mode 100644
index 97ed485b7c..0000000000
---
a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServer.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/**
-*
-* 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.orchestrator.server;
-
-import java.net.InetSocketAddress;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.IServer;
-import org.apache.airavata.common.utils.ServerSettings;
-import
org.apache.airavata.compute.resource.monitoring.ComputationalResourceMonitoringService;
-import
org.apache.airavata.metascheduler.metadata.analyzer.DataInterpreterService;
-import
org.apache.airavata.metascheduler.process.scheduling.engine.rescheduler.ProcessReschedulingService;
-import org.apache.airavata.orchestrator.cpi.OrchestratorService;
-import org.apache.airavata.orchestrator.util.Constants;
-import org.apache.thrift.server.TServer;
-import org.apache.thrift.server.TThreadPoolServer;
-import org.apache.thrift.transport.TServerSocket;
-import org.apache.thrift.transport.TServerTransport;
-import org.apache.thrift.transport.TTransportException;
-import org.quartz.SchedulerException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class OrchestratorServer implements IServer {
-
- private static final Logger logger =
LoggerFactory.getLogger(OrchestratorServer.class);
- private static final String SERVER_NAME = "Orchestrator Server";
- private static final String SERVER_VERSION = "1.0";
-
- private ServerStatus status;
-
- private TServer server;
-
- private static ComputationalResourceMonitoringService monitoringService;
-
- private static ProcessReschedulingService metaschedulerService;
-
- private static DataInterpreterService dataInterpreterService;
-
- // private ClusterStatusMonitorJobScheduler
clusterStatusMonitorJobScheduler;
-
- public OrchestratorServer() {
- setStatus(ServerStatus.STOPPED);
- }
-
- public void StartOrchestratorServer(
- OrchestratorService.Processor<OrchestratorServerHandler>
orchestratorServerHandlerProcessor)
- throws Exception {
- final int serverPort =
Integer.parseInt(ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_PORT,
"8940"));
- try {
- final String serverHost =
ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_HOST, null);
- TServerTransport serverTransport;
- if (serverHost == null) {
- serverTransport = new TServerSocket(serverPort);
- } else {
- InetSocketAddress inetSocketAddress = new
InetSocketAddress(serverHost, serverPort);
- serverTransport = new TServerSocket(inetSocketAddress);
- }
- // server = new TSimpleServer(
- // new
TServer.Args(serverTransport).processor(orchestratorServerHandlerProcessor));
- TThreadPoolServer.Args options = new
TThreadPoolServer.Args(serverTransport);
- options.minWorkerThreads =
-
Integer.parseInt(ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_MIN_THREADS,
"30"));
- server = new
TThreadPoolServer(options.processor(orchestratorServerHandlerProcessor));
- new Thread() {
- public void run() {
- server.serve();
- setStatus(ServerStatus.STARTING);
- logger.info("Starting Orchestrator Server ... ");
- }
- }.start();
- new Thread() {
- public void run() {
- while (!server.isServing()) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- break;
- }
- }
- if (server.isServing()) {
- setStatus(ServerStatus.STARTED);
- logger.info("Started Orchestrator Server on Port " +
serverPort + " ...");
- }
- }
- }.start();
- } catch (TTransportException e) {
- logger.error(e.getMessage());
- setStatus(ServerStatus.FAILED);
- logger.error("Failed to start Orchestrator server on port " +
serverPort + " ...");
- }
- }
-
- public void startClusterStatusMonitoring() throws SchedulerException,
ApplicationSettingsException {
- // clusterStatusMonitorJobScheduler = new
ClusterStatusMonitorJobScheduler();
- //
clusterStatusMonitorJobScheduler.scheduleClusterStatusMonitoring();
-
- try {
- if (monitoringService == null) {
- monitoringService = new
ComputationalResourceMonitoringService();
- monitoringService.setServerStatus(ServerStatus.STARTING);
- }
- if (monitoringService != null &&
!monitoringService.getStatus().equals(ServerStatus.STARTED)) {
- monitoringService.start();
- monitoringService.setServerStatus(ServerStatus.STARTED);
- logger.info("Airavata compute resource monitoring service
started ....");
- }
- } catch (Exception ex) {
- logger.error("Airavata compute resource monitoring service failed
....", ex);
- }
- }
-
- public void startMetaschedulerJobScanning() throws SchedulerException,
ApplicationSettingsException {
- try {
- if (metaschedulerService == null) {
- metaschedulerService = new ProcessReschedulingService();
- metaschedulerService.setServerStatus(ServerStatus.STARTING);
- }
- if (metaschedulerService != null
- &&
!metaschedulerService.getStatus().equals(ServerStatus.STARTED)) {
- metaschedulerService.start();
- metaschedulerService.setServerStatus(ServerStatus.STARTED);
- logger.info("Airavata metascheduler job scanning service
started ....");
- }
- } catch (Exception ex) {
- logger.error("Airavata metascheduler job scanning service failed
....", ex);
- }
- }
-
- public void startMetadataDataAnalyzer() throws SchedulerException,
ApplicationSettingsException {
- try {
- if (dataInterpreterService == null) {
- dataInterpreterService = new DataInterpreterService();
- dataInterpreterService.setServerStatus(ServerStatus.STARTING);
- }
- if (dataInterpreterService != null
- &&
!dataInterpreterService.getStatus().equals(ServerStatus.STARTED)) {
- dataInterpreterService.start();
- dataInterpreterService.setServerStatus(ServerStatus.STARTED);
- logger.info("Airavata data interpreter job scanning service
started ....");
- }
- } catch (Exception ex) {
- logger.error("Airavata data interpreter job scanning service
failed ....", ex);
- }
- }
-
- public static void main(String[] args) {
- try {
- new OrchestratorServer().start();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- }
-
- @Override
- public void start() throws Exception {
- if (ServerSettings.enableClusterStatusMonitoring()) {
- // starting cluster status monitoring
- startClusterStatusMonitoring();
- }
-
- if (ServerSettings.enableMetaschedulerJobScanning()) {
- // starting cluster status monitoring
- startMetaschedulerJobScanning();
- }
-
- if (ServerSettings.enableDataAnalyzerJobScanning()) {
- // starting metadata analyzer
- startMetadataDataAnalyzer();
- }
-
- setStatus(ServerStatus.STARTING);
- OrchestratorService.Processor<OrchestratorServerHandler>
orchestratorService =
- new
OrchestratorService.Processor<OrchestratorServerHandler>(new
OrchestratorServerHandler());
- StartOrchestratorServer(orchestratorService);
- }
-
- @Override
- public void stop() throws Exception {
- if (server != null && server.isServing()) {
- setStatus(ServerStatus.STOPING);
- server.stop();
- }
- if (monitoringService != null) {
- monitoringService.stop();
- monitoringService.setServerStatus(ServerStatus.STOPPED);
- }
- }
-
- @Override
- public void restart() throws Exception {
- stop();
- start();
- }
-
- @Override
- public void configure() throws Exception {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public ServerStatus getStatus() throws Exception {
- return status;
- }
-
- private void setStatus(ServerStatus stat) {
- status = stat;
- status.updateTime();
- }
-
- @Override
- public String getName() {
- return SERVER_NAME;
- }
-
- @Override
- public String getVersion() {
- return SERVER_VERSION;
- }
-}
diff --git
a/airavata-api/src/main/java/org/apache/airavata/patform/monitoring/MonitoringServer.java
b/airavata-api/src/main/java/org/apache/airavata/patform/monitoring/MonitoringServer.java
index 7b28eb1679..8d5e932aa4 100644
---
a/airavata-api/src/main/java/org/apache/airavata/patform/monitoring/MonitoringServer.java
+++
b/airavata-api/src/main/java/org/apache/airavata/patform/monitoring/MonitoringServer.java
@@ -21,35 +21,60 @@ package org.apache.airavata.patform.monitoring;
import io.prometheus.client.exporter.HTTPServer;
import java.io.IOException;
+import org.apache.airavata.common.utils.IServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class MonitoringServer {
+public class MonitoringServer implements IServer {
private static final Logger logger =
LoggerFactory.getLogger(MonitoringServer.class);
+ private static final String SERVER_NAME = "Monitoring Server";
private String host;
private int port;
private HTTPServer httpServer;
+ private ServerStatus status = ServerStatus.STOPPED;
public MonitoringServer(String host, int port) {
this.host = host;
this.port = port;
}
+ @Override
+ public String getName() {
+ return SERVER_NAME;
+ }
+
+ @Override
public void start() throws IOException {
+ setStatus(ServerStatus.STARTING);
try {
logger.info("Starting the monitoring server");
httpServer = new HTTPServer(host, port, true);
+ setStatus(ServerStatus.STARTED);
} catch (IOException e) {
logger.error("Failed to start the monitoring server on host {} na
port {}", host, port, e);
+ setStatus(ServerStatus.FAILED);
}
}
+ @Override
public void stop() {
+ setStatus(ServerStatus.STOPPING);
if (httpServer != null) {
logger.info("Stopping the monitor server");
httpServer.stop();
}
+ setStatus(ServerStatus.STOPPED);
+ }
+
+ @Override
+ public ServerStatus getStatus() {
+ return status;
+ }
+
+ private void setStatus(ServerStatus stat) {
+ status = stat;
+ status.updateTime();
}
}
diff --git
a/airavata-api/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
b/airavata-api/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
deleted file mode 100644
index 8419217240..0000000000
---
a/airavata-api/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
-*
-* 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.service.profile.server;
-
-import java.net.InetSocketAddress;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import org.apache.airavata.common.utils.DBInitConfig;
-import org.apache.airavata.common.utils.DBInitializer;
-import org.apache.airavata.common.utils.IServer;
-import org.apache.airavata.common.utils.ServerSettings;
-import
org.apache.airavata.service.profile.groupmanager.cpi.GroupManagerService;
-import
org.apache.airavata.service.profile.groupmanager.cpi.group_manager_cpiConstants;
-import org.apache.airavata.service.profile.handlers.GroupManagerServiceHandler;
-import org.apache.airavata.service.profile.handlers.IamAdminServicesHandler;
-import
org.apache.airavata.service.profile.handlers.TenantProfileServiceHandler;
-import org.apache.airavata.service.profile.handlers.UserProfileServiceHandler;
-import
org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices;
-import
org.apache.airavata.service.profile.iam.admin.services.cpi.iam_admin_services_cpiConstants;
-import org.apache.airavata.service.profile.tenant.cpi.TenantProfileService;
-import
org.apache.airavata.service.profile.tenant.cpi.profile_tenant_cpiConstants;
-import
org.apache.airavata.service.profile.user.core.utils.UserProfileCatalogDBInitConfig;
-import org.apache.airavata.service.profile.user.cpi.UserProfileService;
-import org.apache.airavata.service.profile.user.cpi.profile_user_cpiConstants;
-import org.apache.thrift.TMultiplexedProcessor;
-import org.apache.thrift.server.TServer;
-import org.apache.thrift.server.TThreadPoolServer;
-import org.apache.thrift.transport.TServerSocket;
-import org.apache.thrift.transport.TServerTransport;
-import org.apache.thrift.transport.TTransportException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Created by goshenoy on 03/08/2017.
- */
-public class ProfileServiceServer implements IServer {
-
- private static final Logger logger =
LoggerFactory.getLogger(ProfileServiceServer.class);
-
- private static final String SERVER_NAME = "Profile Service Server";
- private static final String SERVER_VERSION = "1.0";
-
- private ServerStatus status;
- private TServer server;
- private List<DBInitConfig> dbInitConfigs = Arrays.asList(new
UserProfileCatalogDBInitConfig());
-
- public ProfileServiceServer() {
- setStatus(ServerStatus.STOPPED);
- }
-
- public void updateTime() {}
-
- public Date getTime() {
- return null;
- }
-
- public String getName() {
- return SERVER_NAME;
- }
-
- public String getVersion() {
- return SERVER_VERSION;
- }
-
- public void start() throws Exception {
-
- try {
- setStatus(ServerStatus.STARTING);
-
- logger.info("Initialing profile service databases...");
- for (DBInitConfig dbInitConfig : dbInitConfigs) {
- DBInitializer.initializeDB(dbInitConfig);
- }
- logger.info("Profile service databases initialized successfully");
-
- final int serverPort =
Integer.parseInt(ServerSettings.getProfileServiceServerPort());
-
- // create multiple processors for each profile-service
- var userProfileProcessor = new UserProfileService.Processor<>(new
UserProfileServiceHandler());
- var teneantProfileProcessor = new
TenantProfileService.Processor<>(new TenantProfileServiceHandler());
- var iamAdminServicesProcessor = new
IamAdminServices.Processor<>(new IamAdminServicesHandler());
- var groupmanagerProcessor = new
GroupManagerService.Processor<>(new GroupManagerServiceHandler());
-
- // create a multiplexed processor
- TMultiplexedProcessor profileServiceProcessor = new
TMultiplexedProcessor();
- profileServiceProcessor.registerProcessor(
- profile_user_cpiConstants.USER_PROFILE_CPI_NAME,
userProfileProcessor);
- profileServiceProcessor.registerProcessor(
- profile_tenant_cpiConstants.TENANT_PROFILE_CPI_NAME,
teneantProfileProcessor);
- profileServiceProcessor.registerProcessor(
-
iam_admin_services_cpiConstants.IAM_ADMIN_SERVICES_CPI_NAME,
iamAdminServicesProcessor);
- profileServiceProcessor.registerProcessor(
- group_manager_cpiConstants.GROUP_MANAGER_CPI_NAME,
groupmanagerProcessor);
-
- TServerTransport serverTransport;
- InetSocketAddress inetSocketAddress = new
InetSocketAddress("0.0.0.0", serverPort);
- serverTransport = new TServerSocket(inetSocketAddress);
- TThreadPoolServer.Args options = new
TThreadPoolServer.Args(serverTransport);
- options.minWorkerThreads = 30;
- server = new
TThreadPoolServer(options.processor(profileServiceProcessor));
-
- new Thread() {
- public void run() {
- server.serve();
- setStatus(ServerStatus.STOPPED);
- logger.info("Profile Service Server Stopped.");
- }
- }.start();
- new Thread() {
- public void run() {
- while (!server.isServing()) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- break;
- }
- }
- if (server.isServing()) {
- setStatus(ServerStatus.STARTED);
- logger.info("Starting Profile Service Server on Port "
+ serverPort);
- logger.info("Listening to Profile Service Server
clients ....");
- }
- }
- }.start();
- } catch (TTransportException e) {
- setStatus(ServerStatus.FAILED);
- throw new Exception("Error while starting the Profile Service
Server", e);
- }
- }
-
- public void stop() throws Exception {
-
- if (server != null && server.isServing()) {
- setStatus(ServerStatus.STOPING);
- server.stop();
- }
- }
-
- public void restart() throws Exception {
-
- stop();
- start();
- }
-
- public void configure() throws Exception {}
-
- public ServerStatus getStatus() throws Exception {
- return status;
- }
-
- private void setStatus(ServerStatus stat) {
- status = stat;
- status.updateTime();
- }
-
- public TServer getServer() {
- return server;
- }
-
- public void setServer(TServer server) {
- this.server = server;
- }
-
- public static void main(String[] args) {
- try {
- new ProfileServiceServer().start();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- }
-}