def __init__(self, configuration_file_location, username, password,
              gateway_id):
     self.authenticator = Authenticator(configuration_file_location)
     self.token = self.authenticator.get_token_and_user_info_password_flow(
         username=username, password=password, gateway_id=gateway_id)
     self.gateway_id = gateway_id
     self.username = username
     self.password = password
     self.api_server_client = APIServerClient(configuration_file_location)
class APIServerClientUtil(object):
    def __init__(self, configuration_file_location, username, password,
                 gateway_id):
        self.authenticator = Authenticator(configuration_file_location)
        self.token = self.authenticator.get_token_and_user_info_password_flow(
            username=username, password=password, gateway_id=gateway_id)
        self.gateway_id = gateway_id
        self.username = username
        self.password = password
        self.api_server_client = APIServerClient(configuration_file_location)

    def get_project_id(self, project_name):
        response = self.api_server_client.get_user_projects(
            self.token, self.gateway_id, self.username, 10, 0)
        for project in response:
            if project.name == project_name:
                return project.projectID
        return None

    def get_execution_id(self, application_name):
        response = self.api_server_client.get_all_application_interfaces(
            self.token, self.gateway_id)
        for app in response:
            if app.applicationName == application_name:
                return app.applicationInterfaceId
        return None

    def get_resource_host_id(self, resource_name):
        response = self.api_server_client.get_all_compute_resource_names(
            self.token)
        for k in response.keys():
            if response[k] == resource_name:
                return k
        return None

    def get_group_resource_profile_id(self, group_resource_profile_name):
        response = self.api_server_client.get_group_resource_list(
            self.token, self.gateway_id)
        for x in response:
            if x.groupResourceProfileName == group_resource_profile_name:
                return x.groupResourceProfileId
        return None

    def get_storage_resource_id(self, storage_name):
        response = self.api_server_client.get_all_storage_resource_names(
            self.token)
        for k in response.keys():
            if response[k] == storage_name:
                return k
        return None
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

import logging
from clients.tenant_profile_client import TenantProfileClient

from clients.keycloak_token_fetcher import Authenticator

from airavata.api.error.ttypes import TException

logger = logging.getLogger(__name__)

logger.setLevel(logging.DEBUG)

authenticator = Authenticator();
token = authenticator.get_token_and_user_info_password_flow("default-admin", "123456", "default")

# load GroupManagerClient with default configuration
#client = TenantProfileClient()


# load client with given configuration file (e.g customized_settings.ini)
client = TenantProfileClient('../transport/settings.ini')


def get_all_gateways():
    try:
        gws = client.get_all_gateways(token)
        print("Gateways ", gws)
    except TException:
Beispiel #4
0
    ReplicaLocationCategory, ReplicaPersistentType

from airavata.model.application.io.ttypes import InputDataObjectType

from airavata.model.appcatalog.groupresourceprofile.ttypes import GroupResourceProfile

from airavata.api.error.ttypes import TException, InvalidRequestException, AiravataSystemException, \
    AiravataClientException, AuthorizationException

logger = logging.getLogger(__name__)

logger.setLevel(logging.DEBUG)

configFile = "/Users/isururanawaka/Documents/Cyberwater/poc/resources/settings.ini"

authenticator = Authenticator(configFile)

user_name = "username"
password = "******"
gateway_id = "cyberwater"

token = authenticator.get_token_and_user_info_password_flow(
    username=user_name, password=password, gateway_id=gateway_id)

api_server_client = APIServerClient(configFile)

airavata_util = APIServerClientUtil(configFile,
                                    username=user_name,
                                    password=password,
                                    gateway_id=gateway_id)
data_model_client = DataModelCreationUtil(configFile,
class DataModelCreationUtil(object):
    def __init__(self, configuration_file_location, username, password,
                 gateway_id):
        self.authenticator = Authenticator(configuration_file_location)
        self.token = self.authenticator.get_token_and_user_info_password_flow(
            username=username, password=password, gateway_id=gateway_id)
        self.gateway_id = gateway_id
        self.username = username
        self.password = password
        self.api_server_client = APIServerClient(configuration_file_location)
        self.airavata_util = APIServerClientUtil(configuration_file_location,
                                                 self.username, self.password,
                                                 self.gateway_id)

    def get_experiment_data_model_for_single_application(
            self, project_name, application_name, experiment_name,
            description):
        execution_id = self.airavata_util.get_execution_id(application_name)
        project_id = self.airavata_util.get_project_id(project_name)
        experiment = ExperimentModel()
        experiment.experimentName = experiment_name
        experiment.gatewayId = self.gateway_id
        experiment.userName = self.username
        experiment.description = description
        experiment.projectId = project_id
        experiment.experimentType = ExperimentType.SINGLE_APPLICATION
        experiment.executionId = execution_id
        return experiment

    def configure_computation_resource_scheduling(
            self, experiment_model, computation_resource_name,
            group_resource_profile_name, storageId, node_count,
            total_cpu_count, queue_name, wall_time_limit, experiment_dir_path):
        resource_host_id = self.airavata_util.get_resource_host_id(
            computation_resource_name)
        groupResourceProfileId = self.airavata_util.get_group_resource_profile_id(
            group_resource_profile_name)
        computRes = ComputationalResourceSchedulingModel()
        computRes.resourceHostId = resource_host_id
        computRes.nodeCount = node_count
        computRes.totalCPUCount = total_cpu_count
        computRes.queueName = queue_name
        computRes.wallTimeLimit = wall_time_limit

        userConfigData = UserConfigurationDataModel()
        userConfigData.computationalResourceScheduling = computRes

        userConfigData.groupResourceProfileId = groupResourceProfileId
        userConfigData.storageId = storageId

        userConfigData.experimentDataDir = experiment_dir_path

        experiment_model.userConfigurationData = userConfigData

        return experiment_model

    def register_input_file(self, file_identifier, storage_name, storageId,
                            input_file_name, uploaded_storage_path):
        dataProductModel = DataProductModel()
        dataProductModel.gatewayId = self.gateway_id
        dataProductModel.ownerName = self.username
        dataProductModel.productName = file_identifier
        dataProductModel.dataProductType = DataProductType.FILE

        replicaLocation = DataReplicaLocationModel()
        replicaLocation.storageResourceId = storageId
        replicaLocation.replicaName = "{} gateway data store copy".format(
            input_file_name)
        replicaLocation.replicaLocationCategory = ReplicaLocationCategory.GATEWAY_DATA_STORE
        replicaLocation.filePath = "file://{}:{}".format(
            storage_name, uploaded_storage_path + input_file_name)
        dataProductModel.replicaLocations = [replicaLocation]

        return self.api_server_client.register_data_product(
            self.token, dataProductModel)

    def configure_input_and_outputs(self, experiment_model, input_files,
                                    application_name):
        execution_id = self.airavata_util.get_execution_id(application_name)

        inputs = self.api_server_client.get_application_inputs(
            self.token, execution_id)

        count = 0
        for obj in inputs:
            if isinstance(inputs[count], InputDataObjectType):
                inputs[count].value = input_files[count]
            count = count + 1

        experiment_model.experimentInputs = inputs

        outputs = self.api_server_client.get_application_outputs(
            self.token, execution_id)

        experiment_model.experimentOutputs = outputs

        return experiment_model
Beispiel #6
0
    ReplicaLocationCategory, ReplicaPersistentType

from airavata.model.application.io.ttypes import InputDataObjectType

from airavata.model.appcatalog.groupresourceprofile.ttypes import GroupResourceProfile

from airavata.api.error.ttypes import TException, InvalidRequestException, AiravataSystemException, \
    AiravataClientException, AuthorizationException

logger = logging.getLogger(__name__)

logger.setLevel(logging.DEBUG)

configFile = "/Users/isururanawaka/Documents/Cyberwater/poc/resources/settings.ini"

authenticator = Authenticator(configFile)
token = authenticator.get_token_and_user_info_password_flow(
    "username", "password", "cyberwater")

api_server_client = APIServerClient(configFile)

# fetch all application deployments
deployments = api_server_client.get_all_application_deployments(
    token, "cyberwater")
print(deployments)
# appModuleId  for execution Id

# compute resource names and Ids
compute_resoure_name = api_server_client.get_all_compute_resource_names(token)
print(compute_resoure_name)