Search in sources :

Example 11 with Gateway

use of org.apache.airavata.model.workspace.Gateway in project airavata by apache.

the class SetupNewGateway method setUpGateway.

public static void setUpGateway() {
    Gateway testGateway = new Gateway();
    testGateway.setGatewayId("maven.test.gateway");
    testGateway.setGatewayName("maven test gateway");
    testGateway.setIdentityServerUserName("mavenTest");
    testGateway.setGatewayAdminFirstName("Maven");
    testGateway.setGatewayAdminLastName("Test");
    testGateway.setGatewayAdminEmail("some.man@gmail.com");
    PasswordCredential superAdminCreds = new PasswordCredential();
    superAdminCreds.setGatewayId(testGateway.getGatewayId());
    superAdminCreds.setDescription("test credentials for IS admin creation");
    superAdminCreds.setLoginUserName("airavataAdmin");
    superAdminCreds.setPassword("Airavata@123");
    superAdminCreds.setPortalUserName("superAdmin");
    TenantManagementKeycloakImpl client = new TenantManagementKeycloakImpl();
    try {
        client.addTenant(superAdminCreds, testGateway);
        if (!client.createTenantAdminAccount(superAdminCreds, testGateway, "Test@123")) {
            logger.error("Admin account creation failed !!, please refer error logs for reason");
        }
        Gateway gatewayWithIdAndSecret = client.configureClient(superAdminCreds, testGateway);
        System.out.println(gatewayWithIdAndSecret.getOauthClientId());
        System.out.println(gatewayWithIdAndSecret.getOauthClientSecret());
    } catch (IamAdminServicesException ex) {
        logger.error("Gateway Setup Failed, reason: " + ex.getCause(), ex);
    }
}
Also used : TenantManagementKeycloakImpl(org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) Gateway(org.apache.airavata.model.workspace.Gateway) PasswordCredential(org.apache.airavata.model.credential.store.PasswordCredential)

Example 12 with Gateway

use of org.apache.airavata.model.workspace.Gateway in project airavata by apache.

the class SharingServiceDBEventHandler method onMessage.

@Override
public void onMessage(MessageContext messageContext) {
    log.info("New DB Event message to sharing service.");
    try {
        byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent());
        DBEventMessage dbEventMessage = new DBEventMessage();
        ThriftUtils.createThriftFromBytes(bytes, dbEventMessage);
        log.info("DB Event message to sharing service from " + dbEventMessage.getPublisherService());
        DBEventMessageContext dBEventMessageContext = dbEventMessage.getMessageContext();
        try {
            switch(dBEventMessageContext.getPublisher().getPublisherContext().getEntityType()) {
                case USER_PROFILE:
                    log.info("User profile specific DB Event communicated by " + dbEventMessage.getPublisherService());
                    UserProfile userProfile = new UserProfile();
                    ThriftUtils.createThriftFromBytes(dBEventMessageContext.getPublisher().getPublisherContext().getEntityDataModel(), userProfile);
                    User user = ThriftDataModelConversion.getUser(userProfile);
                    switch(dBEventMessageContext.getPublisher().getPublisherContext().getCrudType()) {
                        case CREATE:
                            log.info("Creating user. User Id : " + user.getUserId());
                            sharingRegistryClient.createUser(user);
                            log.debug("User created. User Id : " + user.getUserId());
                            break;
                        case READ:
                            // FIXME: Remove if not required
                            break;
                        case UPDATE:
                            log.info("Updating user. User Id : " + user.getUserId());
                            sharingRegistryClient.updatedUser(user);
                            log.debug("User updated. User Id : " + user.getUserId());
                            break;
                        case DELETE:
                            log.info("Deleting user. User Id : " + user.getUserId());
                            sharingRegistryClient.deleteUser(user.getDomainId(), user.getUserId());
                            log.debug("User deleted. User Id : " + user.getUserId());
                            break;
                    }
                    break;
                case TENANT:
                    log.info("Tenant specific DB Event communicated by " + dbEventMessage.getPublisherService());
                    Gateway gateway = new Gateway();
                    ThriftUtils.createThriftFromBytes(dBEventMessageContext.getPublisher().getPublisherContext().getEntityDataModel(), gateway);
                    switch(dBEventMessageContext.getPublisher().getPublisherContext().getCrudType()) {
                        case CREATE:
                        case UPDATE:
                            // Only create the domain is it doesn't already exist
                            if (sharingRegistryClient.isDomainExists(gateway.getGatewayId())) {
                                break;
                            }
                            /*
                                Following set of DB operations should happen in a transaction
                                As these are thrift calls we cannot enforce this restriction
                                If something goes wrong, message would get queued again and try to create
                                 DB entities which are already present. We catch DuplicateEntryException and
                                 log as a warning to handle such scenarios and move ahead.
                                 */
                            log.info("Creating domain. Id : " + gateway.getGatewayId());
                            Domain domain = new Domain();
                            domain.setDomainId(gateway.getGatewayId());
                            domain.setName(gateway.getGatewayName());
                            domain.setDescription("Domain entry for " + domain.name);
                            try {
                                sharingRegistryClient.createDomain(domain);
                                log.debug("Domain created. Id : " + gateway.getGatewayId());
                            } catch (DuplicateEntryException ex) {
                                log.warn("DuplicateEntryException while consuming TENANT create message, ex: " + ex.getMessage() + ", Domain Id : " + gateway.getGatewayId(), ex);
                            }
                            // Creating Entity Types for each domain
                            log.info("Creating entity type. Id : " + domain.domainId + ":PROJECT");
                            org.apache.airavata.sharing.registry.models.EntityType entityType = new org.apache.airavata.sharing.registry.models.EntityType();
                            entityType.setEntityTypeId(domain.domainId + ":PROJECT");
                            entityType.setDomainId(domain.domainId);
                            entityType.setName("PROJECT");
                            entityType.setDescription("Project entity type");
                            try {
                                sharingRegistryClient.createEntityType(entityType);
                                log.debug("Entity type created. Id : " + domain.domainId + ":PROJECT");
                            } catch (DuplicateEntryException ex) {
                                log.warn("DuplicateEntryException while consuming TENANT create message, ex: " + ex.getMessage() + ", Entity Id : " + domain.domainId + ":PROJECT", ex);
                            }
                            log.info("Creating entity type. Id : " + domain.domainId + ":EXPERIMENT");
                            entityType = new org.apache.airavata.sharing.registry.models.EntityType();
                            entityType.setEntityTypeId(domain.domainId + ":EXPERIMENT");
                            entityType.setDomainId(domain.domainId);
                            entityType.setName("EXPERIMENT");
                            entityType.setDescription("Experiment entity type");
                            try {
                                sharingRegistryClient.createEntityType(entityType);
                                log.debug("Entity type created. Id : " + domain.domainId + ":EXPERIMENT");
                            } catch (DuplicateEntryException ex) {
                                log.warn("DuplicateEntryException while consuming TENANT create message, ex: " + ex.getMessage() + ", Entity Id : " + domain.domainId + ":EXPERIMENT", ex);
                            }
                            log.info("Creating entity type. Id : " + domain.domainId + ":FILE");
                            entityType = new org.apache.airavata.sharing.registry.models.EntityType();
                            entityType.setEntityTypeId(domain.domainId + ":FILE");
                            entityType.setDomainId(domain.domainId);
                            entityType.setName("FILE");
                            entityType.setDescription("File entity type");
                            try {
                                sharingRegistryClient.createEntityType(entityType);
                                log.debug("Entity type created. Id : " + domain.domainId + ":FILE");
                            } catch (DuplicateEntryException ex) {
                                log.warn("DuplicateEntryException while consuming TENANT create message, ex: " + ex.getMessage() + ", Entity Id : " + domain.domainId + ":FILE", ex);
                            }
                            // Creating Permission Types for each domain
                            log.info("Creating Permission Type. Id : " + domain.domainId + ":READ");
                            PermissionType permissionType = new PermissionType();
                            permissionType.setPermissionTypeId(domain.domainId + ":READ");
                            permissionType.setDomainId(domain.domainId);
                            permissionType.setName("READ");
                            permissionType.setDescription("Read permission type");
                            try {
                                sharingRegistryClient.createPermissionType(permissionType);
                                log.debug("Permission Type created. Id : " + domain.domainId + ":READ");
                            } catch (DuplicateEntryException ex) {
                                log.warn("DuplicateEntryException while consuming TENANT create message, ex: " + ex.getMessage() + ", Permission Id : " + domain.domainId + ":READ", ex);
                            }
                            log.info("Creating Permission Type. Id : " + domain.domainId + ":WRITE");
                            permissionType = new PermissionType();
                            permissionType.setPermissionTypeId(domain.domainId + ":WRITE");
                            permissionType.setDomainId(domain.domainId);
                            permissionType.setName("WRITE");
                            permissionType.setDescription("Write permission type");
                            try {
                                sharingRegistryClient.createPermissionType(permissionType);
                                log.debug("Permission Type created. Id : " + domain.domainId + ":WRITE");
                            } catch (DuplicateEntryException ex) {
                                log.warn("DuplicateEntryException while consuming TENANT create message, ex: " + ex.getMessage() + ", Permission Id : " + domain.domainId + ":WRITE", ex);
                            }
                            break;
                    }
                    break;
                default:
                    log.error("Handler not defined for " + dBEventMessageContext.getPublisher().getPublisherContext().getEntityType());
            }
        } catch (DuplicateEntryException ex) {
            // log this exception and proceed (do nothing)
            // this exception is thrown mostly when messages are re-consumed in case of some exception, hence ignore
            log.warn("DuplicateEntryException while consuming db-event message, ex: " + ex.getMessage(), ex);
        }
        log.info("Sending ack. Message Delivery Tag : " + messageContext.getDeliveryTag());
        SharingServiceDBEventMessagingFactory.getDBEventSubscriber().sendAck(messageContext.getDeliveryTag());
    } catch (TException e) {
        log.error("Error processing message.", e);
    } catch (ApplicationSettingsException e) {
        log.error("Error fetching application settings.", e);
    } catch (AiravataException e) {
        log.error("Error sending ack. Message Delivery Tag : " + messageContext.getDeliveryTag(), e);
    }
}
Also used : TException(org.apache.thrift.TException) DBEventMessage(org.apache.airavata.model.dbevent.DBEventMessage) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) User(org.apache.airavata.sharing.registry.models.User) UserProfile(org.apache.airavata.model.user.UserProfile) PermissionType(org.apache.airavata.sharing.registry.models.PermissionType) DBEventMessageContext(org.apache.airavata.model.dbevent.DBEventMessageContext) Gateway(org.apache.airavata.model.workspace.Gateway) DuplicateEntryException(org.apache.airavata.model.error.DuplicateEntryException) Domain(org.apache.airavata.sharing.registry.models.Domain) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 13 with Gateway

use of org.apache.airavata.model.workspace.Gateway in project airavata by apache.

the class TenantProfileRepository method getDuplicateGateway.

public Gateway getDuplicateGateway(String gatewayId, String gatewayName, String gatewayURL) throws Exception {
    Gateway gateway = null;
    try {
        Map<String, Object> queryParams = new HashMap<String, Object>();
        queryParams.put(Gateway._Fields.GATEWAY_ID.getFieldName(), gatewayId);
        queryParams.put(Gateway._Fields.GATEWAY_NAME.getFieldName(), gatewayName);
        queryParams.put(Gateway._Fields.GATEWAY_URL.getFieldName(), gatewayURL);
        // Only considered APPROVED or CREATED or DEPLOYED gateways when looking for duplicates
        queryParams.put(Gateway._Fields.GATEWAY_APPROVAL_STATUS.getFieldName(), Arrays.asList(GatewayApprovalStatus.APPROVED.name(), GatewayApprovalStatus.CREATED.name(), GatewayApprovalStatus.DEPLOYED.name()));
        List<Gateway> gatewayList = select(QueryConstants.FIND_DUPLICATE_GATEWAY, 1, 0, queryParams);
        if (!gatewayList.isEmpty()) {
            gateway = gatewayList.get(0);
        }
    } catch (Exception ex) {
        logger.error("Error while searching for duplicate gateway, reason: " + ex.getMessage(), ex);
        throw ex;
    }
    return gateway;
}
Also used : HashMap(java.util.HashMap) Gateway(org.apache.airavata.model.workspace.Gateway)

Example 14 with Gateway

use of org.apache.airavata.model.workspace.Gateway in project airavata by apache.

the class TenantProfileRepository method getGateway.

public Gateway getGateway(String airavataInternalGatewayId) throws Exception {
    Gateway gateway = null;
    try {
        Map<String, Object> queryParam = new HashMap<String, Object>();
        queryParam.put(Gateway._Fields.AIRAVATA_INTERNAL_GATEWAY_ID.getFieldName(), airavataInternalGatewayId);
        List<Gateway> gatewayList = select(QueryConstants.FIND_GATEWAY_BY_INTERNAL_ID, 1, 0, queryParam);
        if (!gatewayList.isEmpty()) {
            gateway = gatewayList.get(0);
        }
    } catch (Exception ex) {
        logger.error("Error while getting gateway, reason: " + ex.getMessage(), ex);
        throw ex;
    }
    return gateway;
}
Also used : HashMap(java.util.HashMap) Gateway(org.apache.airavata.model.workspace.Gateway)

Example 15 with Gateway

use of org.apache.airavata.model.workspace.Gateway in project airavata by apache.

the class SampleEchoExperiment method registerGateway.

private String registerGateway() throws TException {
    Gateway gateway = new Gateway();
    gateway.setGatewayName(gatewayId);
    gateway.setGatewayId(gatewayId);
    gateway.setGatewayApprovalStatus(GatewayApprovalStatus.APPROVED);
    return airavataClient.addGateway(new AuthzToken(""), gateway);
}
Also used : Gateway(org.apache.airavata.model.workspace.Gateway) AuthzToken(org.apache.airavata.model.security.AuthzToken)

Aggregations

Gateway (org.apache.airavata.model.workspace.Gateway)24 TException (org.apache.thrift.TException)13 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)8 AuthzToken (org.apache.airavata.model.security.AuthzToken)6 SecurityCheck (org.apache.airavata.service.security.interceptor.SecurityCheck)4 HashMap (java.util.HashMap)3 AiravataException (org.apache.airavata.common.exception.AiravataException)3 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)3 GatewayResourceProfile (org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile)3 AiravataClientException (org.apache.airavata.model.error.AiravataClientException)3 InvalidRequestException (org.apache.airavata.model.error.InvalidRequestException)3 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)3 Airavata (org.apache.airavata.api.Airavata)2 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)2 PasswordCredential (org.apache.airavata.model.credential.store.PasswordCredential)2 DBEventMessage (org.apache.airavata.model.dbevent.DBEventMessage)2 AiravataSystemException (org.apache.airavata.model.error.AiravataSystemException)2 AuthorizationException (org.apache.airavata.model.error.AuthorizationException)2 DuplicateEntryException (org.apache.airavata.model.error.DuplicateEntryException)2 UserProfile (org.apache.airavata.model.user.UserProfile)2