Exemplo n.º 1
0
def getCars(hostname, port, ignore):
    """Uses the GET on car:cars resource to get all cars in the store using RESTCONF"""
    resp = UtilLibrary.get(SettingsLibrary.getCarsUrl(hostname, port), "admin",
                           "admin")
    resp.encoding = "utf-8"
    print(resp.text)
    return resp
Exemplo n.º 2
0
def getClusterRoles(shardName,
                    numOfShards=3,
                    numOfTries=3,
                    sleepBetweenRetriesInSecs=3,
                    port=8181,
                    *ips):
    """Given a shardname (e.g. shard-inventory-config), number of shards and bunch of ips

    determines what role each ip has in an Akka (Raft based) cluster
    result would look like
    {'10.194.126.118':'Leader', '10.194.126.118':'Follower', '10.194.126.117': None}
    """
    dict = {}
    for ip in ips:
        i = 1
        dict[ip] = None
        print "numOfShards => " + str(numOfShards)
        while i <= numOfShards:
            shardMemberName = "member-" + str(i) + "-" + shardName
            j = 1
            print 'j => ' + str(j)
            print 'numOfTries => ' + str(numOfTries)
            while int(j) <= int(numOfTries):
                print("Try number " + str(j))
                try:
                    print("getting role of " + ip + "  for shardName = " +
                          shardMemberName)
                    url = SettingsLibrary.getJolokiaURL(
                        ip, str(port), str(i), shardName)
                    print url
                    resp = UtilLibrary.get(url)
                    print(resp)
                    if resp.status_code != 200:
                        sleep(sleepBetweenRetriesInSecs)
                        continue
                    print(resp.text)
                    data = json.loads(resp.text)
                    if 'value' in data:
                        dataValue = data['value']
                        print("datavalue RaftState is", dataValue['RaftState'])
                        dict[ip] = dataValue['RaftState']
                except:
                    e = sys.exc_info()[0]
                    print("Try" + str(j) +
                          ":An error occurred when finding leader on" + ip +
                          " for shardName:" + shardMemberName)
                    print(e)
                    sleep(sleepBetweenRetriesInSecs)
                    continue
                finally:
                    j = j + 1
            if dict[ip] is not None:
                break
            i = i + 1
    return dict
def getPersons(hostname, port, ignore):
    """Uses the GET on people:people resource to get all persons in the store using RESTCONF

    <note>
        This also returns the dummy entry created for routed RPC
        with personId being user0
    </note>
    """
    resp = UtilLibrary.get(SettingsLibrary.getPersonsUrl(hostname, port), "admin", "admin")
    resp.encoding = 'utf-8'
    print(resp.text)
    return resp
Exemplo n.º 4
0
def getPersons(hostname, port, ignore):
    """Uses the GET on people:people resource to get all persons in the store using RESTCONF

    <note>
        This also returns the dummy entry created for routed RPC
        with personId being user0
    </note>
    """
    resp = UtilLibrary.get(SettingsLibrary.getPersonsUrl(hostname, port), "admin", "admin")
    resp.encoding = 'utf-8'
    print(resp.text)
    return resp
def getClusterRoles(shardName, numOfShards=3, numOfTries=3, sleepBetweenRetriesInSecs=1, port=8181, *ips):
    """Given a shardname (e.g. shard-inventory-config), number of shards and bunch of ips

    determines what role each ip has in an Akka (Raft based) cluster
    result would look like
    {'10.194.126.118':'Leader', '10.194.126.118':'Follower', '10.194.126.117': None}
    """
    dict = {}
    for ip in ips:
        i = 1
        dict[ip] = None

        while i <= numOfShards:
            shardMemberName = "member-" + str(i) + "-" + shardName
            j = 1

            while j <= numOfTries:
                print("Try number " + str(j))
                try:
                    print("finding if" + ip + "is leader for shardName =" + shardMemberName)
                    url = SettingsLibrary.getJolokiaURL(ip, str(port), str(i), shardName)
                    resp = UtilLibrary.get(url)
                    print(resp)
                    if resp.status_code != 200:
                        sleep(sleepBetweenRetriesInSecs)
                        continue
                    print(resp.text)
                    data = json.loads(resp.text)
                    if 'value' in data:
                        dataValue = data['value']
                        print("datavalue RaftState is", dataValue['RaftState'])
                        if dataValue['RaftState'] == 'Follower':
                            dict[ip] = 'Follower'
                            break
                        elif dataValue['RaftState'] == 'Leader':
                            dict[ip] = 'Leader'
                except:
                    e = sys.exc_info()[0]
                    print("Try" + str(j) + ":An error occurred when finding leader on" + ip +
                          " for shardName:" + shardMemberName)
                    print(e)
                    sleep(sleepBetweenRetriesInSecs)
                    continue
                finally:
                    j = j + 1

            if dict[ip] is not None:
                break
            i = i + 1

    return dict
Exemplo n.º 6
0
def getClusterRoles(shardName,
                    numOfShards=3,
                    numOfTries=3,
                    sleepBetweenRetriesInSecs=1,
                    port=8181,
                    *ips):
    dict = {}
    for ip in ips:
        i = 1
        dict[ip] = None
        bFollower = 0
        while i <= numOfShards:
            shardMemberName = "member-" + str(i) + "-" + shardName
            j = 1

            while j <= numOfTries:
                print "Try number " + str(j)
                try:
                    print "finding if" + ip + "is leader for shardName =" + shardMemberName
                    url = SettingsLibrary.getJolokiaURL(
                        ip, str(port), str(i), shardName)
                    resp = UtilLibrary.get(url)
                    print resp
                    if (resp.status_code != 200):
                        continue
                    data = json.loads(resp.text)
                    if ('value' in data):
                        dataValue = data['value']
                        if (dataValue['RaftState'] == 'Follower'):
                            dict[ip] = 'Follower'
                            break
                        elif (dataValue['RaftState'] == 'Leader'):
                            dict[ip] = 'Leader'
                except:
                    e = sys.exc_info()[0]
                    print "Try" + str(
                        j
                    ) + ":An error occurred when finding leader on" + ip + " for shardName:" + shardMemberName
                    print e
                    sleep(sleepBetweenRetriesInSecs)
                    continue
                finally:
                    j = j + 1

            if (dict[ip] != None):
                break
            i = i + 1

    return dict
Exemplo n.º 7
0
def getCarPersonMappings(hostname, port, ignore):
    """Uses the GET on car-people:car-people resource

    to get all car-persons entry in the store using RESTCONF
    <note>
        This also returns the dummy entry created for routed RPC
        with personId being user0
    </note>
    """
    resp = UtilLibrary.get(SettingsLibrary.getCarPersonUrl(hostname, port),
                           "admin", "admin")
    resp.encoding = "utf-8"
    print(resp)

    return resp
def getClusterRoles(shardName,numOfShards=3,numOfTries=3,sleepBetweenRetriesInSecs=1,port=8181,*ips):
    dict={}
    for ip in ips:
      i=1
      dict[ip]=None
      bFollower = 0
      while i <= numOfShards:
        shardMemberName = "member-"+str(i)+"-"+shardName;
        j=1

        while j <= numOfTries:
            print "Try number "+str(j)
            try:
                print "finding if"+ ip +"is leader for shardName ="+shardMemberName
                url = SettingsLibrary.getJolokiaURL(ip,str(port),str(i),shardName)
                resp = UtilLibrary.get(url)
                print resp
                if(resp.status_code != 200):
                    continue
                data = json.loads(resp.text)
                if('value' in data):
                    dataValue = data['value']
                    if(dataValue['RaftState']=='Follower'):
                        dict[ip]='Follower'
                        break;
                    elif(dataValue['RaftState']=='Leader'):
                        dict[ip]='Leader'
            except:
                e = sys.exc_info()[0]
                print "Try"+str(j)+":An error occurred when finding leader on"+ip+" for shardName:" +shardMemberName
                print e
                sleep(sleepBetweenRetriesInSecs)
                continue
            finally:
                j=j+1

        if(dict[ip]!=None):
            break;
        i=i+1

    return dict
def getCarPersonMappings(hostname,port,ignore):
    resp = UtilLibrary.get(SettingsLibrary.getCarPersonUrl(hostname,port),"admin","admin")
    resp.encoding = 'utf-8'
    print (resp)

    return resp
def getPersons(hostname,port,ignore):
    resp = UtilLibrary.get(SettingsLibrary.getPersonsUrl(hostname,port),"admin","admin")
    resp.encoding = 'utf-8'
    print (resp.text)
    return resp
Exemplo n.º 11
0
def getCars(hostname, port, ignore):
    """Uses the GET on car:cars resource to get all cars in the store using RESTCONF"""
    resp = UtilLibrary.get(SettingsLibrary.getCarsUrl(hostname, port), "admin", "admin")
    resp.encoding = 'utf-8'
    print(resp.text)
    return resp
Exemplo n.º 12
0
def getCarPersonMappings(hostname,port,ignore):
    resp = UtilLibrary.get(SettingsLibrary.getCarPersonUrl(hostname,port),"admin","admin")
    resp.encoding = 'utf-8'
    print (resp)

    return resp
Exemplo n.º 13
0
def getPersons(hostname,port,ignore):
    resp = UtilLibrary.get(SettingsLibrary.getPersonsUrl(hostname,port),"admin","admin")
    resp.encoding = 'utf-8'
    print (resp.text)
    return resp