Example #1
0
    def execute(self, path, uri, params):

        if (path is not None):
            command = singletonURIHelperInstance.getUri(
                self.COMPONENT_TYPE, "catalog")
            requestUrl = command.format(path)
        else:
            command = singletonURIHelperInstance.getUri(
                self.COMPONENT_TYPE, "get-service")
            requestUrl = command.format(uri)

        paramsDict = common.toDict(params)
        #If the label object is null, then it shows an error
        if (not (paramsDict.has_key("label"))):
            paramsDict["label"] = ""

        query = None
        if (params is not None):
            for key, value in paramsDict.iteritems():
                if (query is None):
                    query = "?" + key + "=" + value
                else:
                    query = query + "&" + key + "=" + value
            if (query is not None):
                requestUrl = requestUrl + query
        # The requestUrl has '' as a  string instead of an empty string.
        requestUrl = requestUrl.replace("''", "")

        (s, h) = common.service_json_request(self.__ipAddr, self.__port,
                                             "POST", requestUrl, None, None)
        o = common.json_decode(s)

        return o
Example #2
0
    def execute(self, path, uri, params):

        if (path is not None):
            command = singletonURIHelperInstance.getUri(
                self.COMPONENT_TYPE, "catalog")
            requestUrl = command.format(path)
        else:
            command = singletonURIHelperInstance.getUri(
                self.COMPONENT_TYPE, "get-service")
            requestUrl = command.format(uri)

        paramsDict = common.toDict(params)
        #If the label object is null, then it shows an error
        if(not(paramsDict.has_key("label"))):
            paramsDict["label"]=""        

        query = None
        if (params is not None):
            for key, value in paramsDict.iteritems():
                if (query is None):
                    query = "?" + key + "=" + value
                else:
                    query = query + "&" + key + "=" + value
            if (query is not None):
                requestUrl = requestUrl + query
        # The requestUrl has '' as a  string instead of an empty string.
        requestUrl=requestUrl.replace("''","")  

        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "POST", requestUrl, None, None)
        o = common.json_decode(s)

        return o
Example #3
0
    def get_catalog(self, uriPath, xml=False):

        if (uriPath is None):
            uriPath = ""
        elif (uriPath.startswith("/") is False):
            uriPath = "/" + uriPath

        command = singletonURIHelperInstance.getUri(
            self.COMPONENT_TYPE, "catalog")
        port = self.__port
        if(len(uriPath) == 0):
            port = common.getenv('VIPR_UI_PORT')
        (s, h) = common.service_json_request(self.__ipAddr, port, "GET",
                                             command.format(uriPath),
                                             None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')

        if (inactive):
            return None
        if (xml):
            (s, h) = common.service_json_request(self.__ipAddr, port, "GET",
                                                 command.format(uriPath),
                                                 None, None, xml)
            return s
        else:
            return o
    def update(self, uri, name, type, hourOfDay, length, lengthType, dayOfWeek, dayOfMonth, lastDayOfMonth=False):

        request = dict()

        if name is not None:
            request["label"] = name

        if type is not None:
            request["executionWindowType"] = type

        if hourOfDay is not None:
            request["hourOfDayInUTC"] = hourOfDay

        if length is not None:
            request["executionWindowLength"] = length

        if lengthType is not None:
            request["executionWindowLengthType"] = lengthType

        if dayOfWeek is not None:
            request["dayOfWeek"] = dayOfWeek

        if dayOfMonth is not None:
            request["dayOfMonth"] = dayOfMonth

        if lastDayOfMonth is not None:
            request["lastDayOfMonth"] = lastDayOfMonth

        body = json.dumps(request)

        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "show")
        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "PUT", command.format(uri), body)
        o = common.json_decode(s)
        return o
Example #5
0
 def rollback_task_by_uri(self, taskid):
     command = singletonURIHelperInstance.getUri(
         self.COMPONENT_TYPE,
         "rollback")
     (s, h) = common.service_json_request(self.__ipAddr, self.__port, "POST",
                                          command.format(taskid),
                                          None)
Example #6
0
 def reject(self, uri):
     command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                 "reject")
     (s, h) = common.service_json_request(self.__ipAddr,
                                          self.__port, "POST",
                                          command.format(uri), None, None)
     return s
Example #7
0
 def __get_quota_uri(self, resource_type, resource_uri):
     return (
         singletonURIHelperInstance.getUri(
             resource_type,
             "quota").format(
             resource_uri)
     )
Example #8
0
    def get_catalog(self, uriPath, xml=False):

        if (uriPath is None):
            uriPath = ""
        elif (uriPath.startswith("/") is False):
            uriPath = "/" + uriPath

        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "catalog")
        port = self.__port
        if (len(uriPath) == 0):
            port = common.getenv('VIPR_UI_PORT')
        (s, h) = common.service_json_request(self.__ipAddr, port, "GET",
                                             command.format(uriPath), None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')

        if (inactive):
            return None
        if (xml):
            (s, h) = common.service_json_request(self.__ipAddr, port, "GET",
                                                 command.format(uriPath), None,
                                                 None, xml)
            return s
        else:
            return o
Example #9
0
 def delete(self, uri):
     command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                 "show")
     (s, h) = common.service_json_request(self.__ipAddr,
                                          self.__port, "DELETE",
                                          command.format(uri), None)
     return s
Example #10
0
 def reject(self, uri):
     command = singletonURIHelperInstance.getUri(
         self.COMPONENT_TYPE, "reject")
     (s, h) = common.service_json_request(
         self.__ipAddr, self.__port, "POST",
         command.format(uri), None, None)
     return s
Example #11
0
    def list(self):
        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "list")
        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET",
                                             command, None)
        o = common.json_decode(s)

        return o
Example #12
0
    def get_descriptor(self, uri):
        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "get-descriptor")
        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET",
                                             command.format(uri), None, None)
        o = common.json_decode(s)

        return o
 def delete(self, uri):
     command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                 "show")
     (s, h) = common.service_json_request(self.__ipAddr, self.__port,
                                          "DELETE",
                                          command.format(uri),
                                          None)
     return s
Example #14
0
    def get_descriptor(self, uri):
        command = singletonURIHelperInstance.getUri(
            self.COMPONENT_TYPE, "get-descriptor")
        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET",
                                             command.format(uri),
                                             None, None)
        o = common.json_decode(s)

        return o
    def list(self):
        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "list")
        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET",
                                             command,
                                             None)
        o = common.json_decode(s)

        return o
Example #16
0
def get_tasks_by_taskid(componentType, task_id, ipAddr, port):

    task_uri_constant = singletonURIHelperInstance.getUri(
        componentType, "task_by_id")
    (s, h) = service_json_request(ipAddr, port, "GET",
                                  task_uri_constant.format(task_id), None)
    if (not s):
        return None
    o = json_decode(s)
    return o
Example #17
0
def get_tasks_by_taskid(componentType, task_id, ipAddr, port):
      
            task_uri_constant = singletonURIHelperInstance.getUri(
                componentType, "task_by_id")
            (s, h) = service_json_request(
                ipAddr, port, "GET",
                task_uri_constant.format(task_id), None)
            if (not s):
                return None
            o = json_decode(s)
            return o
Example #18
0
def get_tasks_by_resourceuri(componentType, resource_uri, ipAddr, port):

            task_list_uri_constant = singletonURIHelperInstance.getUri(
                componentType, "tasks_list")
            (s, h) = service_json_request(
                ipAddr, port, "GET",
                task_list_uri_constant.format(resource_uri), None)
            if (not s):
                return []
            o = json_decode(s)
            res = o["task"]
            return res
Example #19
0
    def show_execution_by_uri(self, uri, xml):
        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "show-execution")
        if xml is True:
            (s, h) = common.service_json_request(
                self.__ipAddr, self.__port, "GET", command.format(uri), None, None, xml
            )
            return s
        else:
            (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None)
            o = common.json_decode(s)

            return o
Example #20
0
def get_tasks_by_resourceuri(componentType, resource_uri, ipAddr, port):

    task_list_uri_constant = singletonURIHelperInstance.getUri(
        componentType, "tasks_list")
    (s, h) = service_json_request(ipAddr, port, "GET",
                                  task_list_uri_constant.format(resource_uri),
                                  None)
    if (not s):
        return []
    o = json_decode(s)
    res = o["task"]
    return res
    def create(
        self,
        name,
        tenantname,
        type,
        hourOfDay,
        length,
        lengthType,
        dayOfWeek,
        dayOfMonth,
        minuteOfHour,
        lastDayOfMonth=False,
    ):

        new_request = {
            "tenant": tenantname,
            "hour_of_day_in_utc": hourOfDay,
            "minute_of_hour_in_utc": minuteOfHour,
            "execution_window_length": length,
            "execution_window_length_type": lengthType,
            "execution_window_type": type,
            "day_of_week": dayOfWeek,
            "day_of_month": dayOfMonth,
            "last_day_of_month": lastDayOfMonth,
            "name": name,
        }

        if minuteOfHour is not None:
            new_request["minute_of_hour_in_utc"] = minuteOfHour

        if tenantname is not None:
            from tenant import Tenant

            tenant_obj = Tenant(self.__ipAddr, self.__port)
            try:
                tenant_uri = tenant_obj.tenant_query(None)
            except SOSError as e:
                raise e

            new_request["tenant"] = tenant_uri

        body = json.dumps(new_request)

        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "create")

        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "POST", command, body)
        o = common.json_decode(s)
        return o
Example #22
0
    def create(self,
               name,
               tenantname,
               type,
               hourOfDay,
               length,
               lengthType,
               dayOfWeek,
               dayOfMonth,
               minuteOfHour,
               lastDayOfMonth=False):

        new_request = {
            "tenant": tenantname,
            "hour_of_day_in_utc": hourOfDay,
            "minute_of_hour_in_utc": minuteOfHour,
            "execution_window_length": length,
            "execution_window_length_type": lengthType,
            "execution_window_type": type,
            "day_of_week": dayOfWeek,
            "day_of_month": dayOfMonth,
            "last_day_of_month": lastDayOfMonth,
            "name": name
        }

        if (minuteOfHour is not None):
            new_request["minute_of_hour_in_utc"] = minuteOfHour

        if (tenantname is not None):
            from tenant import Tenant
            tenant_obj = Tenant(self.__ipAddr, self.__port)
            try:
                tenant_uri = tenant_obj.tenant_query(None)
            except SOSError as e:
                raise e

            new_request["tenant"] = tenant_uri

        body = json.dumps(new_request)

        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "create")

        (s, h) = common.service_json_request(self.__ipAddr, self.__port,
                                             "POST", command, body)
        o = common.json_decode(s)
        return o
Example #23
0
    def show_execution_by_uri(self, uri, xml):
        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "show-execution")
        if (xml is True):
            (s, h) = common.service_json_request(self.__ipAddr,
                                                 self.__port, "GET",
                                                 command.format(uri), None,
                                                 None, xml)
            return s
        else:
            (s, h) = common.service_json_request(self.__ipAddr,
                                                 self.__port, "GET",
                                                 command.format(uri), None,
                                                 None)
            o = common.json_decode(s)

            return o
Example #24
0
    def update(self,
               uri,
               name,
               type,
               hourOfDay,
               length,
               lengthType,
               dayOfWeek,
               dayOfMonth,
               lastDayOfMonth=False):

        request = dict()

        if (name is not None):
            request["label"] = name

        if (type is not None):
            request["executionWindowType"] = type

        if (hourOfDay is not None):
            request["hourOfDayInUTC"] = hourOfDay

        if (length is not None):
            request["executionWindowLength"] = length

        if (lengthType is not None):
            request["executionWindowLengthType"] = lengthType

        if (dayOfWeek is not None):
            request["dayOfWeek"] = dayOfWeek

        if (dayOfMonth is not None):
            request["dayOfMonth"] = dayOfMonth

        if (lastDayOfMonth is not None):
            request["lastDayOfMonth"] = lastDayOfMonth

        body = json.dumps(request)

        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "show")
        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "PUT",
                                             command.format(uri), body)
        o = common.json_decode(s)
        return o
Example #25
0
    def get_service(self, uri, xml=False):
        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "get-service")
        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET",
                                             command.format(uri), None, None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')

        if (inactive):
            return None
        if (xml):
            (s, h) = common.service_json_request(self.__ipAddr,
                                                 self.__port, "GET",
                                                 command.format(uri), None,
                                                 None, xml)
            return s
        else:
            return o
Example #26
0
    def get_service(self, uri, xml=False):
        command = singletonURIHelperInstance.getUri(
            self.COMPONENT_TYPE, "get-service")
        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET",
                                             command.format(uri),
                                             None, None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')

        if (inactive):
            return None
        if (xml):
            (s, h) = common.service_json_request(
                self.__ipAddr, self.__port, "GET", command.format(uri),
                None, None, xml)
            return s
        else:
            return o
Example #27
0
def list_tasks(ipAddr,
               port,
               componentType,
               project_name,
               resource_name=None,
               task_id=None):

    resourceSearchUri = singletonURIHelperInstance.getUri(
        componentType, "search_by_project")

    uris = search_by_project(project_name, resourceSearchUri, ipAddr, port)

    if (resource_name):
        for uri in uris:
            resource = show_resource(ipAddr, port, componentType, uri, True)
            if (resource['name'] == resource_name):
                if (not task_id):
                    return get_tasks_by_resourceuri(componentType,
                                                    resource["id"], ipAddr,
                                                    port)

                else:
                    res = get_task_by_resourceuri_and_taskId(
                        componentType, resource["id"], task_id, ipAddr, port)
                    if (res):
                        return res
        raise SOSError(SOSError.NOT_FOUND_ERR,
                       "Resource with name: " + resource_name + " not found")
    elif (task_id):
        for uri in uris:
            res = get_tasks_by_taskid(componentType, task_id, ipAddr, port)
            if (res):
                return res
        raise SOSError(SOSError.NOT_FOUND_ERR,
                       "Task Id: " + task_id + "not found")

    else:
        # resourec_name is not given, get all tasks
        all_tasks = []
        for uri in uris:
            res = get_tasks_by_resourceuri(componentType, uri, ipAddr, port)
            if (res and len(res) > 0):
                all_tasks += res
        return all_tasks
Example #28
0
    def list(self, type, params):
        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "list")
        requestUrl = command.format(type)

        paramsDict = common.toDict(params)

        query = None
        if (params is not None):
            for key, value in paramsDict.iteritems():
                if (query is None):
                    query = "?" + key + "=" + value
                else:
                    query = query + "&" + key + "=" + value
            if (query is not None):
                requestUrl = requestUrl + query

        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET",
                                             requestUrl, None, None)
        o = common.json_decode(s)
        return o
Example #29
0
    def list(self, type, params):
        command = singletonURIHelperInstance.getUri(
            self.COMPONENT_TYPE, "list")
        requestUrl = command.format(type)

        paramsDict = common.toDict(params)

        query = None
        if (params is not None):
            for key, value in paramsDict.iteritems():
                if (query is None):
                    query = "?" + key + "=" + value
                else:
                    query = query + "&" + key + "=" + value
            if (query is not None):
                requestUrl = requestUrl + query

        (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET",
                                             requestUrl,
                                             None, None)
        o = common.json_decode(s)
        return o
Example #30
0
def list_unmanaged_tasks(ipAddr, port, componentType, project_name,
               resource_name=None, task_id=None):

    resourceSearchUri = singletonURIHelperInstance.getUri(
        componentType, "search_by_project")

    uris = search_by_project(project_name, resourceSearchUri, ipAddr, port)

    if(resource_name):
        for uri in uris:
            resource = show_resource(ipAddr, port, componentType,
                                     uri, True)
            if(resource['name'] == resource_name):
                if(not task_id):
                    return get_unmanaged_tasks_by_resourceuri(
                        componentType, resource["id"], ipAddr, port)

                else:
                    res = get_unmanaged_task_by_resourceuri_and_taskId(
                        componentType, resource["id"], task_id, ipAddr, port)
                    if(res):
                        return res
        raise SOSError(SOSError.NOT_FOUND_ERR, "Resource with name: " +
                       resource_name + " not found")
    elif(task_id):
        for uri in uris:
            res = get_tasks_by_taskid(componentType, task_id, ipAddr, port)
            if(res):
                return res
            raise SOSError(SOSError.NOT_FOUND_ERR, "Task Id: " + task_id + "not found")
    
    else:
        # resourec_name is not given, get all tasks
        all_tasks = []
        for uri in uris:
            res = get_tasks_by_resourceuri(componentType, uri, ipAddr, port)
            if(res and len(res) > 0):
                all_tasks += res
        return all_tasks
Example #31
0
def show_resource(ipAddr,
                  port,
                  componentType,
                  uri,
                  show_inactive=False,
                  xml=False):

    showUriConstant = singletonURIHelperInstance.getUri(componentType, "show")
    if (xml):
        (s, h) = service_json_request(ipAddr, port, "GET",
                                      showUriConstant.format(uri), None, None,
                                      xml)
        return s

    (s, h) = service_json_request(ipAddr, port, "GET",
                                  showUriConstant.format(uri), None)
    o = json_decode(s)
    if (show_inactive):
        return o
    inactive = get_node_value(o, 'inactive')
    if (inactive):
        return None
    return o
Example #32
0
def show_resource(ipAddr, port, componentType, uri,
                  show_inactive=False, xml=False):

        showUriConstant = singletonURIHelperInstance.getUri(
            componentType, "show")
        if(xml):
            (s, h) = service_json_request(ipAddr, port,
                                          "GET",
                                          showUriConstant.format(uri),
                                          None, None, xml)
            return s

        (s, h) = service_json_request(ipAddr, port,
                                      "GET",
                                      showUriConstant.format(uri),
                                      None)
        o = json_decode(s)
        if(show_inactive):
            return o
        inactive = get_node_value(o, 'inactive')
        if(inactive):
            return None
        return o
Example #33
0
 def __get_quota_uri(self, resource_type, resource_uri):
     return (singletonURIHelperInstance.getUri(
         resource_type, "quota").format(resource_uri))
Example #34
0
 def rollback_task_by_uri(self, taskid):
     command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                 "rollback")
     (s, h) = common.service_json_request(self.__ipAddr,
                                          self.__port, "POST",
                                          command.format(taskid), None)