def parsePrevSnapshot():
    try:

        with open(ArgUtil.args.prevSnapshotFilePath, 'r') as f:
            content = f.readlines()
            if content[0].strip() is not None:
                return UUID(content[0].strip())
    except:
        return min_uuid_from_time(
            0)  # if not exist, take uuid with epoch beggining time (1/1/1970)
Beispiel #2
0
def journeys_for_spacecraft(spacecraft_name):
    if request.method == 'POST':
        now = datetime.utcnow()
        journey_id = min_uuid_from_time(now)
        start = now
        end = now + timedelta(seconds=1000)
        active = True
        summary = request.get_data(as_text=True)

        astra_service.create_new_journey_for_spacecraft(
            spacecraft_name, journey_id, start, end, active, summary)

        return str(journey_id), 200

    if request.method == 'GET':
        result = astra_service.get_all_journeys_for_spacecraft(spacecraft_name)

        return jsonify(result.current_rows), 200
def main():
    args = parse_arguments()
    ArgUtil.setArgs(args)

    newMostResentSnapshot = min_uuid_from_time(
        datetime.datetime.now().timestamp())
    prevSnapshot = parsePrevSnapshot()
    print('prevSnapshot:' + str(datetime_from_uuid1(prevSnapshot)))
    print('newMostResentSnapshot:' +
          str(datetime_from_uuid1(newMostResentSnapshot)))

    applicationsPath = args.applicationIdsPath
    applicationUUIIdsFromFile = parseApplicationUUIDsFromFile(applicationsPath)
    if args.verbose:
        appIdsStringList = [
            str(appUUID) for appUUID in applicationUUIIdsFromFile
        ]
        print('Application UUIDs from file: ' + str(appIdsStringList))

    contactPoints = args.contactPoints
    cluster = Cluster(contactPoints)
    totalStatusDocumentSplited = 0
    totalResponsesCreated = 0
    try:
        session = cluster.connect()
        print('connecting to cluster: [' + ', '.join(contactPoints) + ']  ...')
        session.execute('use unifiedpush_server')

        for appUUID in applicationUUIIdsFromFile:
            totalResponsesCreated, totalStatusDocumentSplited = \
                workOnApplication(appUUID, session, totalResponsesCreated, totalStatusDocumentSplited, prevSnapshot)

        updateMostResentSnapshot(newMostResentSnapshot)

    finally:
        print('Total number of STATUS document found: ' +
              str(totalStatusDocumentSplited))
        print('Total number of RESPONSE document created: ' +
              str(totalResponsesCreated))
        print('closing cluster connections...')
        cluster.shutdown()
def putResponseIfAbsent(session, responseObject, userUUID, appUUID,
                        maxSnapshotUUID):
    # check if RESPONSE document already exist
    isResponseExist = isResponseDocumentExist(session, 'RESPONSE', userUUID,
                                              appUUID,
                                              responseObject['taskId'])
    if ArgUtil.args.verbose:
        print('isResponseAlreadyExist: ' + str(isResponseExist))

    if not isResponseExist:
        newTimeStampUUID = min_uuid_from_time(
            datetime.datetime.now().timestamp())
        print('inserting new response: appId=' + str(appUUID) +
              ', database=RESPONSE, ' + 'userId=' + str(userUUID) +
              ', snapshot=' + str(newTimeStampUUID) + ', responseObject=' +
              json.dumps(responseObject) + ', document_id=' +
              responseObject['taskId'])
        session.execute(INSERT_DOCUMENT_QUERY, [
            appUUID, 'RESPONSE', userUUID, newTimeStampUUID,
            json.dumps(responseObject), "application/json",
            responseObject['taskId']
        ])
Beispiel #5
0
 def test_min_uuid(self):
     u = util.min_uuid_from_time(0)
     # cassandra does a signed comparison of the remaining bytes
     for i in range(8, 16):
         self.assertEqual(marshal.int8_unpack(u.bytes[i:i + 1]), -128)
 def test_min_uuid(self):
     u = util.min_uuid_from_time(0)
     # cassandra does a signed comparison of the remaining bytes
     for i in range(8, 16):
         self.assertEqual(marshal.int8_unpack(u.bytes[i:i + 1]), -128)