コード例 #1
0
    def createEventSource(self, **kwargs):
        opts = tools.Options(**kwargs)
        type = opts.getOpt("type", "")
        name = opts.getOpt("name", "")
        w = opts.getOpt("window", "")

        if len(type) == 0 or len(name) == 0 or len(w) == 0:
            raise Exception(
                "you must specify type, name and window for each event source")

        eventsource = None
        options = {"name": name, "window": w}

        if type == "url":
            #eventsource = UrlEventSource(self,name=name,window=w)
            pass
        elif type == "code":
            #eventsource = CodeEventSource(self,name=name,window=w)
            pass
        elif type == "csv":
            eventsource = CsvEventSource(self, name=name, window=w)

        if eventsource == None:
            raise Exception("invalid event source type: " + type)

        eventsource.setOpts(**kwargs)

        self.addEventSource(eventsource)

        return (eventsource)
コード例 #2
0
    def load(self,model,**kwargs):
        opts = tools.Options(**kwargs)
        xml = ElementTree.fromstring(str(model))
        xml.set("name",self._project)
        model = ElementTree.tostring(xml,method="xml").decode()
        newmodel = "b64" + b64encode(model.encode("utf-8")).decode()

        if newmodel == self.modelXml:
        #if False:
            if opts.getOpt("overwrite",False) == False and opts.getOpt("force",False) == False:
                return

        if self._config != None:
            self.delete()

        url = self.url

        if self._ns != None:
            url += "/namespaces/" + self._ns

        url += "/espservers/"
        url += self._project

        content = self.getYaml(newmodel,pv = False)
        headers = {"content-type":"application/yaml","accept":"application/json", }
        if self.getOpt("access_token") is not None:
            authorization = "Bearer " + self.getOpt("access_token")
            headers.update({"Authorization": authorization.encode("utf-8")})

        response = requests.post(url,data=content,headers=headers)
        if response.status_code >= 400:
            raise Exception(response.text)

        self.isReady()
コード例 #3
0
 def __init__(self,charts,datasource,**kwargs):
     self._charts = charts
     self._datasource = datasource
     self._options = tools.Options(**kwargs)
     self._dashboard = None
     self._figure = None
     self._data = None
     self._box = None
     self._layout = None
     self._controls = None
コード例 #4
0
 def addPolygons(self, datasource, **kwargs):
     options = tools.Options(**kwargs)
     o = {}
     o["coords"] = options.getOpt("coords")
     o["datasource"] = datasource
     o["layers"] = maps.LayerGroup()
     if options.hasOpt("text"):
         o["text"] = options.getOpt("text")
     self._polygons.append(o)
     self.loadPolygons(o)
     datasource.addDelegate(self)
コード例 #5
0
    def configure(self, config, **kwargs):
        self._config = config

        content = None

        if isinstance(config, str):
            xml = ElementTree.fromstring(config)
        else:
            xml = config

        if len(kwargs) > 0:
            opts = tools.Options(**kwargs)
            content = opts.resolve(content)

        for node in xml.findall("./event-sources/*"):
            name = ""
            w = ""

            if "name" in node.attrib:
                name = node.get("name")
            if "window" in node.attrib:
                w = node.get("window")

            if len(name) == 0 or len(w) == 0:
                raise Exception(
                    "you must specify name and window for each event source")

            type = node.tag
            options = {"name": name, "window": w}
            eventsource = None

            if type == "url-event-source":
                eventsource = UrlEventSource(self, options)
            elif type == "code-event-source":
                eventsource = CodeEventSource(self, options)
            elif type == "csv-event-source":
                eventsource = CsvEventSource(self, name=name, window=w)

            if eventsource == None:
                raise Exception("failed to create event source from \n\n" +
                                xpath.xmlString(node) + "\n")

            self.addEventSource(eventsource)

            eventsource.configure(node)

        for node in xml.findall("./edges/edge"):
            sources = node.get("source").split(" ")
            targets = node.get("target").split(" ")

            for s in sources:
                for t in targets:
                    self.addEdge(s, t)
コード例 #6
0
    def getProjects(self, delegate, **kwargs):
        if tools.supports(delegate, "handleProjects") == False:
            raise Exception(
                "the delegate must implement the handleProjects function")

        url = self.url

        opts = tools.Options(**kwargs)

        if opts.hasOpt("namespace"):
            url += "/namespaces/" + opts.getOpt("namespace")

        url += "/espservers"

        if opts.hasOpt("name"):
            url += "/" + opts.getOpt("name")

        response = requests.get(url)

        if response.status_code == 404:
            if tools.supports(delegate, "notFound"):
                delegate.notFound()
            else:
                raise Exception("error: not found")
            return

        data = response.json()

        if "code" in data and data["code"] == 404:
            s = ""
            if self._ns != None:
                s += self._ns + "/"
            s += self._project

            if tools.supports(delegate, "notFound"):
                delegate.notFound(s)
            else:
                raise Exception("project not found: " + s)
        else:
            kind = data["kind"]
            a = None

            if kind == "ESPServer":
                a = [data]
            elif kind == "ESPServerList":
                a = data["items"]

            delegate.handleProjects(a)
コード例 #7
0
 def addCircles(self, datasource, **kwargs):
     options = tools.Options(**kwargs)
     o = {}
     o["lat"] = options.getOpt("lat")
     o["lon"] = options.getOpt("lon")
     o["datasource"] = datasource
     o["layers"] = maps.LayerGroup()
     if options.hasOpt("radius"):
         value = options.getOpt("radius")
         try:
             num = int(value)
             o["radius"] = num
         except:
             o["radius_field"] = value
     if options.hasOpt("text"):
         o["text"] = options.getOpt("text")
     self._circles.append(o)
     self.loadCircles(o)
     datasource.addDelegate(self)
コード例 #8
0
    def getProject(self,delegate,**kwargs):

        opts = tools.Options(**kwargs)

        namespace = opts.getOpt("namespace")
        name = opts.getOpt("name")

        if (namespace == None or name == None):
            raise Exception("you must specify project namespace and name")

        class Tmp(object):
            def handleProjects(self,projects):
                delegate.handleProject(projects[0])
            def notFound(self):
                if tools.supports(delegate,"notFound"):
                    delegate.notFound()
                else:
                    raise Exception("error: not found")

        self.getProjects(Tmp(),namespace=namespace,name=name)
コード例 #9
0
    def getYaml(self, model, **kwargs):

        opts = tools.Options(**kwargs)

        s = ""

        s += "apiVersion: iot.sas.com/v1alpha1\n"
        s += "kind: ESPServer\n"
        s += "metadata:\n"
        s += "  name: " + self._project + "\n"
        if self._ns != None:
            s += "  namespace: " + self._ns + "\n"
        s += "spec:\n"
        s += "    loadBalancePolicy: \"default\" \n"
        s += "    espProperties:\n"
        s += "      server.xml: \"" + model + "\"\n"
        s += "      meta.meteringhost: \"sas-event-stream-processing-metering-app." + self._ns + "\"\n"
        s += "      meta.meteringport: \"80\"\n"
        s += "    projectTemplate:\n"
        s += "      autoscale:\n"
        s += "        minReplicas: 1\n"
        s += "        maxReplicas: 1\n"
        s += "        metrics:\n"
        s += "        - type: Resource\n"
        s += "          resource:\n"
        s += "            name: cpu\n"
        s += "            target:\n"
        s += "              type: Utilization\n"
        s += "              averageUtilization: 50\n"
        s += "      deployment:\n"
        s += "        spec:\n"
        s += "          selector:\n"
        s += "            matchLabels:\n"
        s += "          template:\n"
        s += "            spec:\n"

        if (self.getOpt("viya", False) == False):
            s += "               volumes:\n"
            s += "               - name: data\n"
            s += "                 persistentVolumeClaim:\n"
            s += "                   claimName: esp-pv\n"

        s += "               containers:\n"
        s += "               - name: ((PROJECT_SERVICE_NAME))\n"
        s += "                 resources:\n"
        s += "                   requests:\n"
        s += "                     memory: \"1Gi\"\n"
        s += "                     cpu: \"1\"\n"
        s += "                   limits:\n"
        s += "                     memory: \"2Gi\"\n"
        s += "                     cpu: \"2\"\n"

        if (self.getOpt("viya", False) == False):
            s += "                 volumeMounts:\n"
            s += "                 - mountPath: /mnt/data\n"
            s += "                   name: data\n"

        s += "    loadBalancerTemplate:\n"
        s += "      deployment:\n"
        s += "        spec:\n"
        s += "          template:\n"
        s += "            spec:\n"
        s += "              containers:\n"
        s += "              - name: ((PROJECT_SERVICE_NAME)) \n"
        s += "access:\n"
        s += "  state: \"Pending\" \n"
        s += "  internalHostName:  foo\n"
        s += "  internalHttpPort:  0\n"
        s += "  externalURL: foo\n"

        return (s)
コード例 #10
0
    def __init__(self,**kwargs):
        self._options = tools.Options(**kwargs)
        self._charts = []

        colormap = self._options.get("colors")
        self._colors = tools.Colors(colormap)
コード例 #11
0
ファイル: viewers.py プロジェクト: smatton/python-esppy
 def __init__(self, visuals, connection, **kwargs):
     self._visuals = visuals
     self._connection = connection
     self._options = tools.Options(**kwargs)
コード例 #12
0
ファイル: dashboard.py プロジェクト: smatton/python-esppy
 def __init__(self, **kwargs):
     self._options = tools.Options(**kwargs)
     self._rows = []
     self._container = None