zoukankan      html  css  js  c++  java
  • Python示例

    http request:put

    # 定义函数:refresh segement
    # curl -X PUT -s --user "****:*****" -H 'Content-Type: application/json' -d '{"startTime":1515283200000, "endTime":1515369600000, "buildType":"REFRESH"}' "*****/kylin/api/cubes/*****/rebuild" || { log "ERROR" "$project" "Build cube failed"; exit 1;}
    
    def refreshOneSegment( kylinBaseUrl,cubeName,userName,pwd,startTimestamp,endTimestamp):
       urlTemp=kylinBaseUrl+"/api/cubes/"+cubeName+"/rebuild"
       dataTemp ={"startTime":startTimestamp, "endTime":endTimestamp, "buildType":"REFRESH"}
       base64stringT = base64.encodestring('%s:%s' % (userName, pwd)).replace('
    ', '')
       requestTemp=urllib2.Request(urlTemp)
       requestTemp.add_header("Authorization", "Basic %s" % base64stringT) 
       requestTemp.add_header("Content-Type", "application/json;charset=UTF-8") 
       requestTemp.add_data(json.dumps(dataTemp))
       request2.get_method = lambda: 'PUT' # or 'DELETE'
       response2 = urllib2.urlopen(request2)
       data2 = response2.read()
       return data2;
    

      

     外部传参

    import urllib
    import urllib2
    import json
    import base64
    import datetime
    import time
    import sys
    
    username="*****"
    password="*****"
    kylinbaseurl='*******'
    startLimitDate=sys.argv[1]
    endLimitDate=sys.argv[2]
    cubeName=sys.argv[3]
    

      

    外部调用

    python Refresh_Kylin_Segments "2018-01-07" "2018-1-10" "******"
    

      

    http request :get

    # 定义函数:get segements
    # curl -X GET --user "****:*****" -H 'Content-Type: application/json' "*****/kylin/api/cubes/*****"
    def getSegmentsBetweenTimeRange(kylinBaseUrl,cubeName,userName,pwd):
       urlTemp=kylinBaseUrl+"/api/cubes/"+cubeName
       base64stringT = base64.encodestring('%s:%s' % (userName, pwd)).replace('
    ', '')
       requestTemp=urllib2.Request(urlTemp)
       requestTemp.add_header("Authorization", "Basic %s" % base64stringT) 
       requestTemp.add_header("Content-Type", "application/json")
       responseTemp = urllib2.urlopen(requestTemp)
       dataTemp = responseTemp.read()
       return dataTemp;
    

      

    json data :

    # 定义函数:get Segments Between Time Range
    def getSegmentsBetweenTimeRange(jsonCubeData,minStartDate,maxEndDate):
       listResult = [];
       decodejsonT = json.loads(jsonCubeData)
       segmentsT=decodejsonT['segments']
       for i in range(0, len(segmentsT)):
        startTimestampT=segmentsT[i]['date_range_start']
        endTimestampT=segmentsT[i]['date_range_end']
        startDateT=datetime.datetime.utcfromtimestamp(startTimestampT/1000)
        endDateT=datetime.datetime.utcfromtimestamp(endTimestampT/1000)
        if ( minStartDate < endDateT and minStartDate >= startDateT):
            listResult.append({"startTimestamp":startTimestampT,"endTimestamp":endTimestampT});
        elif( maxEndDate < endDateT and maxEndDate >= startDateT):
            listResult.append({"startTimestamp":startTimestampT,"endTimestamp":endTimestampT});
       return listResult;
    

      

    list

    # main process
    def main(kylinBaseUrl,cubeName,userName,pwd,startTimestamp,endTimestamp):
        listResult = [];
        jsonCubeDataOne=getCubeInfo(kylinBaseUrl,cubeName,userName,pwd)
        print jsonCubeDataOne
        minStartDate=datetime.datetime.strptime(startLimitDate, "%Y-%m-%d")
        maxEndDate=datetime.datetime.strptime(endLimitDate, "%Y-%m-%d")
        needRefreshSegmentList=getSegmentsBetweenTimeRange(jsonCubeDataOne,minStartDate,maxEndDate)
        print needRefreshSegmentList
        for i in range(0, len(needRefreshSegmentList)):
            startTimestampT=needRefreshSegmentList[i]['startTimestamp']
            endTimestampT=needRefreshSegmentList[i]['endTimestamp']
            oneResult=refreshOneSegment(kylinBaseUrl,cubeName,userName,pwd,startTimestampT,endTimestampT)
            listResult.append(oneResult)
        return listResult
    

      

  • 相关阅读:
    rpm -ivh 这个ivh是干什么的
    记录各种资源链接的吧
    Bootstrap中表单控件状态(验证状态)
    jquery input 实时监听输入
    socket.error: [Errno 98] Address already in use
    bad interpreter: Text file busy
    Linux下安装pip(遇到了python2.6升级为python2.7道路上的坑,原因已经找到,只差临门一脚了,以后补上)
    完全卸载mysql数据库教程
    数字签名证书的事儿(转)
    设计模式-外观模式
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/8252903.html
Copyright © 2011-2022 走看看