Search in sources :

Example 41 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class UserResourceProfileResource method remove.

public void remove(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    CompositeIdentifier ids;
    if (identifier instanceof CompositeIdentifier) {
        ids = (CompositeIdentifier) identifier;
    } else {
        logger.error("Identifier should be a instance of CompositeIdentifier class");
        throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
    }
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
        generator.setParameter(UserResourceProfileConstants.GATEWAY_ID, ids.getSecondLevelIdentifier().toString());
        generator.setParameter(UserResourceProfileConstants.USER_ID, ids.getTopLevelIdentifier().toString());
        Query q = generator.deleteQuery(em);
        q.executeUpdate();
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 42 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class UserResourceProfileResource method getAll.

@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
    List<AppCatalogResource> resourceList = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
        Query q = generator.selectQuery(em);
        List results = q.getResultList();
        if (results.size() != 0) {
            for (Object result : results) {
                UserResourceProfile userResourceProfile = (UserResourceProfile) result;
                UserResourceProfileResource userResourceProfileResource = (UserResourceProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_RESOURCE_PROFILE, userResourceProfile);
                resourceList.add(userResourceProfileResource);
            }
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return resourceList;
}
Also used : EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 43 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class UserResourceProfileResource method save.

public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        UserResourceProfile existingUserResourceProfile = em.find(UserResourceProfile.class, new UserResourceProfilePK(userId, gatewayID));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingUserResourceProfile != null) {
            existingUserResourceProfile.setUpdateTime(AiravataUtils.getCurrentTimestamp());
            if (credentialStoreToken != null) {
                existingUserResourceProfile.setCredentialStoreToken(credentialStoreToken);
            }
            if (identityServerTenant != null) {
                existingUserResourceProfile.setIdentityServerTenant(identityServerTenant);
            }
            if (identityServerPwdCredToken != null) {
                existingUserResourceProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
            }
            em.merge(existingUserResourceProfile);
        } else {
            UserResourceProfile userResourceProfile = new UserResourceProfile();
            userResourceProfile.setGatewayID(gatewayID);
            userResourceProfile.setUserId(userId);
            userResourceProfile.setCreationTime(AiravataUtils.getCurrentTimestamp());
            if (credentialStoreToken != null) {
                userResourceProfile.setCredentialStoreToken(credentialStoreToken);
            }
            if (identityServerTenant != null) {
                userResourceProfile.setIdentityServerTenant(identityServerTenant);
            }
            if (identityServerPwdCredToken != null) {
                userResourceProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
            }
            em.persist(userResourceProfile);
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : UserResourceProfilePK(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfilePK) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 44 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class UserStoragePreferenceResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    CompositeIdentifier ids;
    if (identifier instanceof CompositeIdentifier) {
        ids = (CompositeIdentifier) identifier;
    } else {
        logger.error("Identifier should be a instance of CompositeIdentifier class");
        throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_STORAGE_PREFERENCE);
        generator.setParameter(UserStoragePreferenceConstants.STORAGE_ID, ids.getTopLevelIdentifier().toString());
        generator.setParameter(UserStoragePreferenceConstants.USER_ID, ids.getSecondLevelIdentifier().toString());
        generator.setParameter(UserStoragePreferenceConstants.GATEWAY_ID, ids.getThirdLevelIdentifier().toString());
        Query q = generator.selectQuery(em);
        UserStoragePreference preference = (UserStoragePreference) q.getSingleResult();
        UserStoragePreferenceResource preferenceResource = (UserStoragePreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_STORAGE_PREFERENCE, preference);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return preferenceResource;
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) EntityManager(javax.persistence.EntityManager) CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) UserStoragePreference(org.apache.airavata.registry.core.app.catalog.model.UserStoragePreference)

Example 45 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class ApplicationInterfaceImpl method getApplicationOutputs.

@Override
public List<OutputDataObjectType> getApplicationOutputs(String interfaceId) throws AppCatalogException {
    try {
        ApplicationOutputResource resource = new ApplicationOutputResource();
        List<AppCatalogResource> resources = resource.get(AppCatAbstractResource.AppOutputConstants.INTERFACE_ID, interfaceId);
        return AppCatalogThriftConversion.getAppOutputs(resources);
    } catch (Exception e) {
        logger.error("Error while retrieving app outputs for application " + interfaceId, e);
        throw new AppCatalogException(e);
    }
}
Also used : AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Aggregations

AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)353 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)268 EntityManager (javax.persistence.EntityManager)261 Query (javax.persistence.Query)176 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)176 ArrayList (java.util.ArrayList)94 HashMap (java.util.HashMap)70 Map (java.util.Map)54 List (java.util.List)42 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)22 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)14 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)13 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)10 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)8 GatewayProfile (org.apache.airavata.registry.core.app.catalog.model.GatewayProfile)6 ResourceJobManager (org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager)6 StorageResource (org.apache.airavata.registry.core.app.catalog.model.StorageResource)6 Initialize (org.apache.airavata.app.catalog.util.Initialize)5 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)5 GSISSHSubmission (org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission)5