making corrections to user profile service code
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/8f6f2183 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/8f6f2183 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/8f6f2183 Branch: refs/heads/develop Commit: 8f6f2183c42b1ce1432b93b4ade892f1f122fb2d Parents: e0fbde2 Author: Anuj Bhandar <bhandar.a...@gmail.com> Authored: Tue Jan 24 18:45:59 2017 -0500 Committer: Anuj Bhandar <bhandar.a...@gmail.com> Committed: Tue Jan 24 18:45:59 2017 -0500 ---------------------------------------------------------------------- .../user-profile-service/.classpath | 26 -- .../user-profile/user-profile-service/pom.xml | 14 +- .../server/UserProfileHandler.java | 85 ---- .../server/UserProfileServer.java | 141 ------ .../user/profile/server/UserProfileHandler.java | 102 ++++ .../user/profile/server/UserProfileServer.java | 159 +++++++ modules/user-profile/user-profile-stubs/pom.xml | 34 +- .../api/exception/RegistryServiceException.java | 2 +- .../airavata/userprofile/crude/cpi/Test.java | 14 - .../crude/cpi/UserProfileCrudeService.java | 462 ++++++++++--------- .../cpi/user_profile_crud_cpiConstants.java | 16 + .../component-cpis/generate-cpi-stubs.sh | 9 +- .../component-cpis/user-profile-crud-cpi.thrift | 58 +++ 13 files changed, 622 insertions(+), 500 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-service/.classpath ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/.classpath b/modules/user-profile/user-profile-service/.classpath deleted file mode 100644 index af1430b..0000000 --- a/modules/user-profile/user-profile-service/.classpath +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" output="target/classes" path="src/main/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="src" output="target/test-classes" path="src/test/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="output" path="target/classes"/> -</classpath> http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-service/pom.xml ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/pom.xml b/modules/user-profile/user-profile-service/pom.xml index 3e35699..0839735 100644 --- a/modules/user-profile/user-profile-service/pom.xml +++ b/modules/user-profile/user-profile-service/pom.xml @@ -2,26 +2,28 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata</artifactId> + <version>0.17-SNAPSHOT</version> + <relativePath>../../../pom.xml</relativePath> + </parent> <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.airavata</groupId> <artifactId>user-profile-service</artifactId> - <version>0.17-SNAPSHOT</version> + <name>Airavata user profile service</name> + <description>Module to expose a user profile registry as a thrift service</description> <dependencies> - <dependency> <groupId>org.apache.airavata</groupId> <artifactId>airavata-commons</artifactId> <version>${project.version}</version> </dependency> - <dependency> <groupId>org.apache.airavata</groupId> <artifactId>user-profile-stubs</artifactId> <version>${project.version}</version> </dependency> - </dependencies> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileHandler.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileHandler.java b/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileHandler.java deleted file mode 100644 index f07426c..0000000 --- a/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.apache.airavata.user.profile.server; - -import org.apache.airavata.model.user.UserProfile; -import org.apache.airavata.registry.api.exception.RegistryServiceException; -import org.apache.airavata.registry.core.entities.workspacecatalog.UserProfileEntity; -import org.apache.airavata.registry.core.repositories.workspacecatalog.UserProfileRepository; -import org.apache.airavata.userprofile.crude.cpi.UserProfileCrudeService; -import org.apache.thrift.TException; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Created by Airavata on 11/11/2016. - */ -public class UserProfileHandler implements UserProfileCrudeService.Iface { - - private UserProfileRepository userProfileRepository; - - public UserProfileHandler() { - - userProfileRepository = new UserProfileRepository(UserProfile.class, UserProfileEntity.class); - } - - public String addUserProfile(UserProfile userProfile) throws RegistryServiceException, TException { - - userProfileRepository.create(userProfile); - - if (null != userProfile) - return userProfile.getUserId(); - - return null; - } - - public boolean updateUserProfile(UserProfile userProfile) throws RegistryServiceException, TException { - - try { - userProfileRepository.update(userProfile); - } catch (Exception e) { - - return false; - } - - return true; - } - - public UserProfile getUserProfileById(String userId, String gatewayId) throws RegistryServiceException, TException { - - - UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); - - return userProfile; - } - - public boolean deleteUserProfile(String userId) throws RegistryServiceException, TException { - - boolean deleteResult = userProfileRepository.delete(userId); - - return deleteResult; - } - - - - public List<UserProfile> getAllUserProfilesInGateway(String gatewayId, int offset, int limit) throws RegistryServiceException, TException { - List<UserProfile> usersInGateway = userProfileRepository.getAllUserProfilesInGateway(gatewayId, offset, limit); - return usersInGateway; - } - - - public UserProfile getUserProfileByName(String userName, String gatewayId) throws RegistryServiceException, TException { - - UserProfile userProfile = userProfileRepository.getUserProfileByNameAndGateWay(userName, gatewayId); - return userProfile; - } - - public boolean doesUserExist(String userName, String gatewayId) throws RegistryServiceException, TException { - - UserProfile userProfile = userProfileRepository.getUserProfileByNameAndGateWay(userName, gatewayId); - - if (null != userProfile) - return true; - return false; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileServer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileServer.java b/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileServer.java deleted file mode 100644 index 53fd539..0000000 --- a/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileServer.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.apache.airavata.user.profile.server; - -import org.apache.airavata.common.utils.IServer; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.userprofile.crude.cpi.UserProfileCrudeService; -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; - -import java.net.InetSocketAddress; -import java.util.Date; - -/** - * Created by abhij on 11/11/2016. - */ -public class UserProfileServer implements IServer { - - private final static Logger logger = LoggerFactory.getLogger(UserProfileServer.class); - - private static final String SERVER_NAME = "User Profile Server"; - private static final String SERVER_VERSION = "1.0"; - - private IServer.ServerStatus status; - private TServer server; - - public UserProfileServer() { - setStatus(IServer.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); - final int serverPort = Integer.parseInt(ServerSettings.getUserProfileServerPort()); - final String serverHost = ServerSettings.getUserProfileServerHost(); - UserProfileCrudeService.Processor processor = new UserProfileCrudeService.Processor(new UserProfileHandler()); - - 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(ServerStatus.STOPPED); - logger.info("User Profile 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 User Profile Server on Port " + serverPort); - logger.info("Listening to User Profile server clients ...."); - } - } - }.start(); - } catch (TTransportException e) { - setStatus(ServerStatus.FAILED); - throw new Exception("Error while starting the User Profile service", 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(IServer.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 UserProfileServer().start(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileHandler.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileHandler.java b/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileHandler.java new file mode 100644 index 0000000..369ec1c --- /dev/null +++ b/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileHandler.java @@ -0,0 +1,102 @@ +/* + * + * 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.user.profile.server; + +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.registry.api.exception.RegistryServiceException; +import org.apache.airavata.registry.core.entities.workspacecatalog.UserProfileEntity; +import org.apache.airavata.registry.core.repositories.workspacecatalog.UserProfileRepository; +import org.apache.airavata.userprofile.crude.cpi.UserProfileCrudeService; +import org.apache.thrift.TException; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class UserProfileHandler implements UserProfileCrudeService.Iface { + + private UserProfileRepository userProfileRepository; + + public UserProfileHandler() { + + userProfileRepository = new UserProfileRepository(UserProfile.class, UserProfileEntity.class); + } + + public String addUserProfile(UserProfile userProfile) throws RegistryServiceException, TException { + + userProfileRepository.create(userProfile); + + if (null != userProfile) + return userProfile.getUserId(); + + return null; + } + + public boolean updateUserProfile(UserProfile userProfile) throws RegistryServiceException, TException { + + try { + userProfileRepository.update(userProfile); + } catch (Exception e) { + + return false; + } + + return true; + } + + public UserProfile getUserProfileById(String userId, String gatewayId) throws RegistryServiceException, TException { + + + UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); + + return userProfile; + } + + public boolean deleteUserProfile(String userId) throws RegistryServiceException, TException { + + boolean deleteResult = userProfileRepository.delete(userId); + + return deleteResult; + } + + + + public List<UserProfile> getAllUserProfilesInGateway(String gatewayId, int offset, int limit) throws RegistryServiceException, TException { + List<UserProfile> usersInGateway = userProfileRepository.getAllUserProfilesInGateway(gatewayId, offset, limit); + return usersInGateway; + } + + + public UserProfile getUserProfileByName(String userName, String gatewayId) throws RegistryServiceException, TException { + + UserProfile userProfile = userProfileRepository.getUserProfileByNameAndGateWay(userName, gatewayId); + return userProfile; + } + + public boolean doesUserExist(String userName, String gatewayId) throws RegistryServiceException, TException { + + UserProfile userProfile = userProfileRepository.getUserProfileByNameAndGateWay(userName, gatewayId); + + if (null != userProfile) + return true; + return false; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServer.java b/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServer.java new file mode 100644 index 0000000..a45d2d4 --- /dev/null +++ b/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServer.java @@ -0,0 +1,159 @@ +/* + * + * 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.user.profile.server; + +import org.apache.airavata.common.utils.IServer; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.userprofile.crude.cpi.UserProfileCrudeService; +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; + +import java.net.InetSocketAddress; +import java.util.Date; + +public class UserProfileServer implements IServer { + + private final static Logger logger = LoggerFactory.getLogger(UserProfileServer.class); + + private static final String SERVER_NAME = "User Profile Server"; + private static final String SERVER_VERSION = "1.0"; + + private IServer.ServerStatus status; + private TServer server; + + public UserProfileServer() { + setStatus(IServer.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); + final int serverPort = Integer.parseInt(ServerSettings.getUserProfileServerPort()); + final String serverHost = ServerSettings.getUserProfileServerHost(); + UserProfileCrudeService.Processor processor = new UserProfileCrudeService.Processor(new UserProfileHandler()); + + 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(ServerStatus.STOPPED); + logger.info("User Profile 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 User Profile Server on Port " + serverPort); + logger.info("Listening to User Profile server clients ...."); + } + } + }.start(); + } catch (TTransportException e) { + setStatus(ServerStatus.FAILED); + throw new Exception("Error while starting the User Profile service", 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(IServer.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 UserProfileServer().start(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-stubs/pom.xml ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-stubs/pom.xml b/modules/user-profile/user-profile-stubs/pom.xml index 3f9bce8..59c72eb 100644 --- a/modules/user-profile/user-profile-stubs/pom.xml +++ b/modules/user-profile/user-profile-stubs/pom.xml @@ -11,14 +11,16 @@ language governing permissions and limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> - <artifactId>user-profile</artifactId> <groupId>org.apache.airavata</groupId> + <artifactId>airavata</artifactId> <version>0.17-SNAPSHOT</version> + <relativePath>../../../pom.xml</relativePath> </parent> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> <artifactId>user-profile-stubs</artifactId> - + <name>Airavata user profile service stubs</name> + <description>thrift generated user profile service stubs</description> <dependencies> <dependency> @@ -32,4 +34,30 @@ <version>${project.version}</version> </dependency> </dependencies> + + <build> + <plugins> + <plugin> + <groupId>com.google.code.maven-replacer-plugin</groupId> + <artifactId>replacer</artifactId> + <version>${maven.replacer.plugin.version}</version> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>replace</goal> + </goals> + </execution> + </executions> + <configuration> + <includes> + <include>${basedir}/src/main/java/org/apache/airavata/**/*.java</include> + </includes> + <token>, date = ".*"</token> + <value> </value> + </configuration> + </plugin> + </plugins> + </build> + </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java index 154ea74..7ada9c5 100644 --- a/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java +++ b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java @@ -50,7 +50,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-11-18") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)") public class RegistryServiceException extends TException implements org.apache.thrift.TBase<RegistryServiceException, RegistryServiceException._Fields>, java.io.Serializable, Cloneable, Comparable<RegistryServiceException> { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RegistryServiceException"); http://git-wip-us.apache.org/repos/asf/airavata/blob/8f6f2183/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/crude/cpi/Test.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/crude/cpi/Test.java b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/crude/cpi/Test.java deleted file mode 100644 index 9914906..0000000 --- a/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/crude/cpi/Test.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.apache.airavata.userprofile.crude.cpi; - -import org.apache.airavata.model.user.UserProfile; - -/** - * Created by abhij on 11/17/2016. - */ -public class Test { - - public static void main(String args[]) { - - System.out.println(); - } -}