Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 49F45200C30 for ; Tue, 7 Mar 2017 23:17:40 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 4875A160B68; Tue, 7 Mar 2017 22:17:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 73D9A160B82 for ; Tue, 7 Mar 2017 23:17:38 +0100 (CET) Received: (qmail 52343 invoked by uid 500); 7 Mar 2017 22:17:37 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 52214 invoked by uid 99); 7 Mar 2017 22:17:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Mar 2017 22:17:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0FF44DFF75; Tue, 7 Mar 2017 22:17:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: scnakandala@apache.org To: commits@airavata.apache.org Date: Tue, 07 Mar 2017 22:17:40 -0000 Message-Id: In-Reply-To: <4b58c5d26f8341c68d95f07beb0452c9@git.apache.org> References: <4b58c5d26f8341c68d95f07beb0452c9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [05/11] airavata git commit: Add profile-service-core project with handlers archived-at: Tue, 07 Mar 2017 22:17:40 -0000 Add profile-service-core project with handlers Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/4e58ef78 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/4e58ef78 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/4e58ef78 Branch: refs/heads/user-profile Commit: 4e58ef78b9193ee5a3bfa9df9e0632987470e736 Parents: 5982619 Author: Gourav Shenoy Authored: Tue Mar 7 13:12:50 2017 -0500 Committer: Gourav Shenoy Committed: Tue Mar 7 13:12:50 2017 -0500 ---------------------------------------------------------------------- airavata-services/profile-service/pom.xml | 1 + .../profile-gateway-core/pom.xml | 61 ++++ .../gateway/core/GwyResourceProfile.java | 78 +++++ .../gateway/core/entities/GatewayProfile.java | 100 ++++++ .../core/impl/GwyResourceProfileImpl.java | 148 ++++++++ .../core/resources/GatewayProfileResource.java | 342 +++++++++++++++++++ .../profile/gateway/core/util/JPAConstants.java | 33 ++ .../profile/gateway/core/util/JPAUtils.java | 67 ++++ .../gateway/core/util/QueryConstants.java | 16 + .../profile/gateway/core/util/Utils.java | 155 +++++++++ .../src/main/resources/META-INF/persistence.xml | 32 ++ .../handlers/GatewayProfileServiceHandler.java | 20 ++ .../profile-service/profile-user-core/pom.xml | 1 + pom.xml | 3 + 14 files changed, 1057 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/pom.xml ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/pom.xml b/airavata-services/profile-service/pom.xml index d6ee487..556f6de 100644 --- a/airavata-services/profile-service/pom.xml +++ b/airavata-services/profile-service/pom.xml @@ -20,6 +20,7 @@ profile-service-stubs profile-user-core + profile-gateway-core profile-service-server http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/pom.xml ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/pom.xml b/airavata-services/profile-service/profile-gateway-core/pom.xml new file mode 100644 index 0000000..9eb0f0b --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/pom.xml @@ -0,0 +1,61 @@ + + + + profile-service + org.apache.airavata + 0.17-SNAPSHOT + ../pom.xml + + + 4.0.0 + profile-gateway-core + Profile Gateway Core + + + 10.11.1.1 + 2.18.1 + false + 5.1.34 + 2.2.0 + + + + + net.sf.dozer + dozer + 5.4.0 + + + org.apache.openjpa + openjpa-all + ${openjpa.version} + + + mysql + mysql-connector-java + ${mysql.connector.version} + + + org.apache.derby + derby + ${derby.version} + + + org.apache.derby + derbyclient + ${derby.version} + + + org.apache.derby + derbynet + ${derby.version} + + + org.apache.derby + derbytools + ${derby.version} + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/GwyResourceProfile.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/GwyResourceProfile.java b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/GwyResourceProfile.java new file mode 100644 index 0000000..6c3b961 --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/GwyResourceProfile.java @@ -0,0 +1,78 @@ +/** + * 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.gateway.core; + +import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference; +import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; +import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference; + +import java.util.List; + +public interface GwyResourceProfile { + /** + * This method will add a gateway profile + * @param gatewayProfile gateway profile + * @return gateway id + */ + String addGatewayResourceProfile(GatewayResourceProfile gatewayProfile) throws Exception; + + /** + * This method will update a gateway profile + * @param gatewayId unique gateway id + * @param updatedProfile updated profile + */ + void updateGatewayResourceProfile(String gatewayId, GatewayResourceProfile updatedProfile) throws Exception; + + /** + * + * @param gatewayId + * @return + */ + GatewayResourceProfile getGatewayProfile(String gatewayId) throws Exception; + + /** + * This method will remove a gateway profile + * @param gatewayId unique gateway id + * @return true or false + */ + boolean removeGatewayResourceProfile(String gatewayId) throws Exception; + + /** + * This method will check whether gateway profile exists + * @param gatewayId unique gateway id + * @return true or false + */ + boolean isGatewayResourceProfileExists(String gatewayId) throws Exception; + + /** + * This method will get gateway profile ids + * @param gatewayName + * @return + * @throws Exception + */ + List getGatewayProfileIds(String gatewayName) throws Exception; + + /** + * This method will return all gateway profiles + * @return + * @throws Exception + */ + List getAllGatewayProfiles() throws Exception; +} http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/entities/GatewayProfile.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/entities/GatewayProfile.java b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/entities/GatewayProfile.java new file mode 100644 index 0000000..6c5796b --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/entities/GatewayProfile.java @@ -0,0 +1,100 @@ +/* + * + * 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.gateway.core.entities; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; +import java.sql.Timestamp; + +@Entity +@Table(name = "GATEWAY_PROFILE") +public class GatewayProfile implements Serializable { + @Id + @Column(name = "GATEWAY_ID") + private String gatewayID; + @Column(name = "CREATION_TIME") + private Timestamp creationTime; + + @Column(name = "UPDATE_TIME") + private Timestamp updateTime; + + @Column(name = "CS_TOKEN") + private String credentialStoreToken; + + @Column(name = "IDENTITY_SERVER_TENANT") + private String identityServerTenant; + + @Column(name = "IDENTITY_SERVER_PWD_CRED_TOKEN") + private String identityServerPwdCredToken; + + public Timestamp getCreationTime() { + return creationTime; + } + + public void setCreationTime(Timestamp creationTime) { + this.creationTime = creationTime; + } + + public Timestamp getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Timestamp updateTime) { + this.updateTime = updateTime; + } + + + public String getGatewayID() { + return gatewayID; + } + + public void setGatewayID(String gatewayID) { + this.gatewayID = gatewayID; + } + + public String getCredentialStoreToken() { + return credentialStoreToken; + } + + public void setCredentialStoreToken(String credentialStoreToken) { + this.credentialStoreToken = credentialStoreToken; + } + + public String getIdentityServerTenant() { + return identityServerTenant; + } + + public void setIdentityServerTenant(String identityServerTenant) { + this.identityServerTenant = identityServerTenant; + } + + public String getIdentityServerPwdCredToken() { + return identityServerPwdCredToken; + } + + public void setIdentityServerPwdCredToken(String identityServerPwdCredToken) { + this.identityServerPwdCredToken = identityServerPwdCredToken; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GwyResourceProfileImpl.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GwyResourceProfileImpl.java b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GwyResourceProfileImpl.java new file mode 100644 index 0000000..9430779 --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GwyResourceProfileImpl.java @@ -0,0 +1,148 @@ +/* + * + * 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.gateway.core.impl; + +import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; +import org.apache.airavata.service.profile.gateway.core.GwyResourceProfile; +import org.apache.airavata.service.profile.gateway.core.resources.GatewayProfileResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class GwyResourceProfileImpl implements GwyResourceProfile { + + private final static Logger logger = LoggerFactory.getLogger(GwyResourceProfileImpl.class); + + @Override + public String addGatewayResourceProfile(GatewayResourceProfile gatewayProfile) throws Exception { + try { + GatewayProfileResource profileResource = new GatewayProfileResource(); + if (!gatewayProfile.getGatewayID().equals("")){ + profileResource.setGatewayID(gatewayProfile.getGatewayID()); + } + if (gatewayProfile.getCredentialStoreToken()!= null){ + profileResource.setCredentialStoreToken(gatewayProfile.getCredentialStoreToken()); + } + if (gatewayProfile.getIdentityServerTenant() != null){ + profileResource.setIdentityServerTenant(gatewayProfile.getIdentityServerTenant()); + } + if (gatewayProfile.getIdentityServerPwdCredToken() != null){ + profileResource.setIdentityServerPwdCredToken(gatewayProfile.getIdentityServerPwdCredToken()); + } + profileResource.setGatewayID(gatewayProfile.getGatewayID()); + profileResource.save(); + return profileResource.getGatewayID(); + } catch (Exception e) { + logger.error("Error while saving gateway profile, exception: " + e, e); + throw e; + } + } + + @Override + public void updateGatewayResourceProfile(String gatewayId, GatewayResourceProfile updatedProfile) throws Exception { + try { + GatewayProfileResource existingGP = new GatewayProfileResource().getByID(gatewayId); + existingGP.setCredentialStoreToken(updatedProfile.getCredentialStoreToken()); + existingGP.setIdentityServerTenant(updatedProfile.getIdentityServerTenant()); + existingGP.setIdentityServerPwdCredToken(updatedProfile.getIdentityServerPwdCredToken()); + existingGP.save(); + } catch (Exception e) { + logger.error("Error while updating gateway profile, exception: " + e, e); + throw e; + } + } + + @Override + public GatewayResourceProfile getGatewayProfile(String gatewayId) throws Exception { + try { + GatewayProfileResource gw = new GatewayProfileResource().getByID(gatewayId); + GatewayResourceProfile gatewayProfile = new GatewayResourceProfile(); + gatewayProfile.setGatewayID(gw.getGatewayID()); + gatewayProfile.setCredentialStoreToken(gw.getCredentialStoreToken()); + gatewayProfile.setIdentityServerTenant(gw.getIdentityServerTenant()); + gatewayProfile.setIdentityServerPwdCredToken(gw.getIdentityServerPwdCredToken()); + return gatewayProfile; + } catch (Exception e) { + logger.error("Error while retrieving gateway profile, exception: " + e, e); + throw e; + } + } + + @Override + public boolean removeGatewayResourceProfile(String gatewayId) throws Exception { + try { + GatewayProfileResource resource = new GatewayProfileResource(); + resource.remove(gatewayId); + return true; + } catch (Exception e) { + logger.error("Error while deleting gateway profile, exception: " + e, e); + throw e; + } + } + + @Override + public boolean isGatewayResourceProfileExists(String gatewayId) throws Exception { + try { + GatewayProfileResource resource = new GatewayProfileResource(); + return resource.isExists(gatewayId); + } catch (Exception e) { + logger.error("Error while retrieving gateway profile, exception: " + e, e); + throw e; + } + } + + @Override + public List getGatewayProfileIds(String gatewayName) throws Exception { + try { + GatewayProfileResource profileResource = new GatewayProfileResource(); + List gatewayIds = profileResource.getGatewayProfileIds(gatewayName); + return gatewayIds; + } catch (Exception e) { + logger.error("Error while retrieving gateway ids, exception: " + e, e); + throw e; + } + } + + @Override + public List getAllGatewayProfiles() throws Exception { + try { + List gatewayResourceProfileList = new ArrayList<>(); + List resourceList = new GatewayProfileResource().getAll(); + if (resourceList != null && !resourceList.isEmpty()){ + for (GatewayProfileResource gw : resourceList) { + GatewayResourceProfile gatewayProfile = new GatewayResourceProfile(); + gatewayProfile.setGatewayID(gw.getGatewayID()); + gatewayProfile.setCredentialStoreToken(gw.getCredentialStoreToken()); + gatewayProfile.setIdentityServerTenant(gw.getIdentityServerTenant()); + gatewayProfile.setIdentityServerPwdCredToken(gw.getIdentityServerPwdCredToken()); + gatewayResourceProfileList.add(gatewayProfile); + } + } + return gatewayResourceProfileList; + } catch (Exception e) { + logger.error("Error while retrieving gateway ids, exception: " + e, e); + throw e; + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayProfileResource.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayProfileResource.java b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayProfileResource.java new file mode 100644 index 0000000..ec78d1b --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayProfileResource.java @@ -0,0 +1,342 @@ +/** + * 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.gateway.core.resources; + +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.service.profile.gateway.core.entities.GatewayProfile; +import org.apache.airavata.service.profile.gateway.core.util.JPAUtils; +import org.apache.airavata.service.profile.gateway.core.util.QueryConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.sql.Timestamp; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +public class GatewayProfileResource { + private final static Logger logger = LoggerFactory.getLogger(GatewayProfileResource.class); + + private String gatewayID; + private Timestamp createdTime; + private Timestamp updatedTime; + private String credentialStoreToken; + private String identityServerTenant; + private String identityServerPwdCredToken; + + public Timestamp getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(Timestamp createdTime) { + this.createdTime = createdTime; + } + + public Timestamp getUpdatedTime() { + return updatedTime; + } + + public void setUpdatedTime(Timestamp updatedTime) { + this.updatedTime = updatedTime; + } + + public String getCredentialStoreToken() { + return credentialStoreToken; + } + + public void setCredentialStoreToken(String credentialStoreToken) { + this.credentialStoreToken = credentialStoreToken; + } + + public String getIdentityServerTenant() { + return identityServerTenant; + } + + public void setIdentityServerTenant(String identityServerTenant) { + this.identityServerTenant = identityServerTenant; + } + + public String getIdentityServerPwdCredToken() { + return identityServerPwdCredToken; + } + + public void setIdentityServerPwdCredToken(String identityServerPwdCredToken) { + this.identityServerPwdCredToken = identityServerPwdCredToken; + } + + public void remove(String gatewayID) throws Exception { + EntityManager em = null; + try { + em = JPAUtils.getEntityManager(); + em.getTransaction().begin(); + GatewayProfile gp = em.find(GatewayProfile.class, gatewayID); + em.remove(gp); + em.getTransaction().commit(); + if (em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw e; + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public GatewayProfileResource getByID(String gatewayID) throws Exception { + EntityManager em = null; + try { + em = JPAUtils.getEntityManager(); + em.getTransaction().begin(); + GatewayProfile gatewayProfile = em.find(GatewayProfile.class, gatewayID); + GatewayProfileResource gatewayProfileResource = JPAUtils.createGatewayProfile(gatewayProfile); + em.getTransaction().commit(); + if (em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + return gatewayProfileResource; + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw e; + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @SuppressWarnings("unchecked") + public List getListByID(String gatewayID) throws Exception { + List gatewayProfileResources = new ArrayList(); + EntityManager em = null; + try { + em = JPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q = em.createQuery(MessageFormat.format(QueryConstants.FIND_GATEWAY_PROFILE_BY_ID, gatewayID)); + List results = q.getResultList(); + if (results.size() != 0) { + for (GatewayProfile gatewayProfile : results) { + GatewayProfileResource gatewayProfileResource = JPAUtils.createGatewayProfile(gatewayProfile); + gatewayProfileResources.add(gatewayProfileResource); + } + } + em.getTransaction().commit(); + if (em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw e; + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return gatewayProfileResources; + } + + @SuppressWarnings("unchecked") + public List getAll() throws Exception { + List resourceList = new ArrayList(); + EntityManager em = null; + try { + em = JPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q = em.createQuery(QueryConstants.GET_ALL_GATEWAY_PROFILES); + List results = q.getResultList(); + if (results.size() != 0) { + for (GatewayProfile gatewayProfile : results) { + GatewayProfileResource gatewayProfileResource = JPAUtils.createGatewayProfile(gatewayProfile); + resourceList.add(gatewayProfileResource); + } + } + em.getTransaction().commit(); + if (em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw e; + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return resourceList; + } + + @SuppressWarnings("unchecked") + public List getGatewayProfileIds(String gatewayID) throws Exception { + List gatewayProfileResourceIDs = new ArrayList(); + EntityManager em = null; + try { + em = JPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q = em.createQuery(MessageFormat.format(QueryConstants.FIND_GATEWAY_PROFILE_BY_ID, gatewayID)); + List results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + GatewayProfile gatewayProfile = (GatewayProfile) result; + gatewayProfileResourceIDs.add(gatewayProfile.getGatewayID()); + } + } + em.getTransaction().commit(); + if (em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw e; + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return gatewayProfileResourceIDs; + } + + public void save() throws Exception { + EntityManager em = null; + try { + em = JPAUtils.getEntityManager(); + GatewayProfile existingGatewayProfile = em.find(GatewayProfile.class, gatewayID); + if (em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + + em = JPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingGatewayProfile != null) { + existingGatewayProfile.setUpdateTime(AiravataUtils.getCurrentTimestamp()); + if (credentialStoreToken != null){ + existingGatewayProfile.setCredentialStoreToken(credentialStoreToken); + } + if (identityServerTenant != null){ + existingGatewayProfile.setIdentityServerTenant(identityServerTenant); + } + if (identityServerPwdCredToken != null){ + existingGatewayProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken); + } + em.merge(existingGatewayProfile); + } else { + GatewayProfile gatewayProfile = new GatewayProfile(); + gatewayProfile.setGatewayID(gatewayID); + gatewayProfile.setCreationTime(AiravataUtils.getCurrentTimestamp()); + if (credentialStoreToken != null){ + gatewayProfile.setCredentialStoreToken(credentialStoreToken); + } + if (identityServerTenant != null){ + gatewayProfile.setIdentityServerTenant(identityServerTenant); + } + if (identityServerPwdCredToken != null){ + gatewayProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken); + } + em.persist(gatewayProfile); + } + em.getTransaction().commit(); + if (em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw e; + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public boolean isExists(Object identifier) throws Exception { + EntityManager em = null; + try { + em = JPAUtils.getEntityManager(); + GatewayProfile gatewayProfile = em.find(GatewayProfile.class, identifier); + if (em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + return gatewayProfile != null; + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw e; + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getGatewayID() { + return gatewayID; + } + + public void setGatewayID(String gatewayID) { + this.gatewayID = gatewayID; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAConstants.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAConstants.java b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAConstants.java new file mode 100644 index 0000000..d9bec3c --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAConstants.java @@ -0,0 +1,33 @@ +/* + * + * 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.gateway.core.util; +public class JPAConstants { + public static final String KEY_JDBC_URL = "gateway.profile.catalog.registry.jdbc.url"; + public static final String KEY_JDBC_USER = "gateway.profile.catalog.registry.jdbc.user"; + public static final String KEY_JDBC_PASSWORD = "gateway.profile.catalog.registry.jdbc.password"; + public static final String KEY_JDBC_DRIVER = "gateway.profile.catalog.registry.jdbc.driver"; + // TODO: is this needed? + public static final String KEY_DERBY_START_ENABLE = "gateway.profile.catalog.start.derby.server.mode"; + public static final String VALIDATION_QUERY = "gateway.profile.catalog.validationQuery"; + public static final String JPA_CACHE_SIZE = "gateway.profile.catalog.jpa.cache.size"; + public static final String ENABLE_CACHING = "gateway.profile.catalog.cache.enable"; +} http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java new file mode 100644 index 0000000..ba5dda4 --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java @@ -0,0 +1,67 @@ + +package org.apache.airavata.service.profile.gateway.core.util; + +import org.apache.airavata.service.profile.gateway.core.entities.GatewayProfile; +import org.apache.airavata.service.profile.gateway.core.resources.GatewayProfileResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.*; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by goshenoy on 3/6/17. + */ +public class JPAUtils { + + private final static Logger logger = LoggerFactory.getLogger(JPAUtils.class); + + private static final String PERSISTENCE_UNIT_NAME = "gateway_profile_catalog"; + + @PersistenceUnit(unitName = PERSISTENCE_UNIT_NAME) + private static EntityManagerFactory factory; + + @PersistenceContext(unitName = PERSISTENCE_UNIT_NAME) + private static EntityManager entityManager; + + public static EntityManager getEntityManager() { + if (factory == null) { + String connectionProperties = "DriverClassName=" + Utils.getJDBCDriver() + "," + "Url=" + + Utils.getJDBCURL() + "?autoReconnect=true," + + "Username=" + Utils.getJDBCUser() + "," + "Password=" + Utils.getJDBCPassword() + + ",validationQuery=" + Utils.getValidationQuery(); + logger.info(connectionProperties); + Map properties = new HashMap(); + properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource"); + properties.put("openjpa.ConnectionProperties", connectionProperties); + properties.put("openjpa.DynamicEnhancementAgent", "true"); + properties.put("openjpa.RuntimeUnenhancedClasses", "warn"); + properties.put("openjpa.RemoteCommitProvider", "sjvm"); + properties.put("openjpa.Log", "DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO"); + properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); + properties.put("openjpa.jdbc.QuerySQLCache", "false"); + properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72," + + " PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000, autoReconnect=true"); + factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties); + } + + entityManager = factory.createEntityManager(); + return entityManager; + } + + public static GatewayProfileResource createGatewayProfile(GatewayProfile gatewayProfile) { + GatewayProfileResource resource = new GatewayProfileResource(); + if (gatewayProfile != null) { + resource.setGatewayID(gatewayProfile.getGatewayID()); + resource.setCreatedTime(gatewayProfile.getCreationTime()); + resource.setCredentialStoreToken(gatewayProfile.getCredentialStoreToken()); + resource.setIdentityServerTenant(gatewayProfile.getIdentityServerTenant()); + resource.setIdentityServerPwdCredToken(gatewayProfile.getIdentityServerPwdCredToken()); + if (gatewayProfile.getUpdateTime() != null) { + resource.setUpdatedTime(gatewayProfile.getUpdateTime()); + } + } + return resource; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java new file mode 100644 index 0000000..f56ba6d --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java @@ -0,0 +1,16 @@ +package org.apache.airavata.service.profile.gateway.core.util; + +import org.apache.airavata.model.user.UserProfile; + +/** + * Created by goshenoy on 11/11/2016. + */ +public interface QueryConstants { + + + + String FIND_GATEWAY_PROFILE_BY_ID = "SELECT gp FROM GatewayProfile gp " + + "where gp.gatewayID='{}'"; + + String GET_ALL_GATEWAY_PROFILES = "SELECT gp FROM GatewayProfile gp"; +} http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/Utils.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/Utils.java b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/Utils.java new file mode 100644 index 0000000..6bf28e2 --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/Utils.java @@ -0,0 +1,155 @@ +/* + * + * 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.gateway.core.util; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URI; + + +public class Utils { + private final static Logger logger = LoggerFactory.getLogger(Utils.class); + + public static String getJDBCFullURL(){ + String jdbcUrl = getJDBCURL(); + String jdbcUser = getJDBCUser(); + String jdbcPassword = getJDBCPassword(); + jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword; + return jdbcUrl; + } + + public static String getJDBCURL(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_URL); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getHost(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getHost(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static int getPort(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getPort(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return -1; + } + } + + public static int getJPACacheSize (){ + try { + String cache = ServerSettings.getSetting(JPAConstants.JPA_CACHE_SIZE, "5000"); + return Integer.parseInt(cache); + }catch (Exception e){ + logger.error(e.getMessage(), e); + return -1; + } + } + + public static String isCachingEnabled (){ + try { + return ServerSettings.getSetting(JPAConstants.ENABLE_CACHING, "true"); + }catch (Exception e){ + logger.error(e.getMessage(), e); + return "true"; + } + } + + public static String getDBType(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getScheme(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static boolean isDerbyStartEnabled(){ + try { + String s = ServerSettings.getSetting(JPAConstants.KEY_DERBY_START_ENABLE); + if("true".equals(s)){ + return true; + } + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return false; + } + return false; + } + + public static String getJDBCUser(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_USER); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getValidationQuery(){ + try { + return ServerSettings.getSetting(JPAConstants.VALIDATION_QUERY); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getJDBCPassword(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_PASSWORD); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + + } + + public static String getJDBCDriver(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_DRIVER); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-gateway-core/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-gateway-core/src/main/resources/META-INF/persistence.xml b/airavata-services/profile-service/profile-gateway-core/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..2482da5 --- /dev/null +++ b/airavata-services/profile-service/profile-gateway-core/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,32 @@ + + + + + org.apache.openjpa.persistence.PersistenceProviderImpl + + true + + + + + http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java index 082be22..ae87215 100644 --- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java +++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java @@ -1,3 +1,23 @@ +/* + * + * 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.handlers; import org.apache.airavata.model.workspace.Gateway; http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/airavata-services/profile-service/profile-user-core/pom.xml ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-user-core/pom.xml b/airavata-services/profile-service/profile-user-core/pom.xml index 8eba129..ef0814a 100644 --- a/airavata-services/profile-service/profile-user-core/pom.xml +++ b/airavata-services/profile-service/profile-user-core/pom.xml @@ -11,6 +11,7 @@ 4.0.0 profile-user-core + Profile User Core 10.11.1.1 http://git-wip-us.apache.org/repos/asf/airavata/blob/4e58ef78/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d32cda8..de29f2c 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,9 @@ 3.0 + + profile-gateway-core + org.apache