def coordinate( self ): attributes = { "created":sdb_now(offset=self.time_offset) } attributes.update( self.network_information ) d = self.sdb.putAttributes( self.aws_sdb_coordination_domain, self.uuid, attributes, replace=attributes.keys() ) d.addCallback( self._coordinateCallback ) d.addErrback( self._coordinateErrback )
def createReservation( self, function_name, **kwargs ): if not isinstance( function_name, str ): for key in self.functions: if self.functions[key]["function"] == function_name: function_name = key break if function_name not in self.functions: raise Exception("Function %s does not exist." % function_name ) function = self.functions[ function_name ] filtered_kwargs = {} for key in function["required_arguments"]: if key in kwargs: filtered_kwargs[key] = convertToUTF8( kwargs[key] ) else: raise Exception("Required parameter '%s' not found. Required parameters are %s. Optional parameters are %s." % (key, function["required_arguments"], function["optional_arguments"] )) for key in function["optional_arguments"]: if key in kwargs: filtered_kwargs[key] = convertToUTF8( kwargs[key] ) if function["interval"] > 0: reserved_arguments = {} reserved_arguments["reservation_function_name"] = function_name reserved_arguments["reservation_created"] = sdb_now(offset=self.time_offset) reserved_arguments["reservation_next_request"] = reserved_arguments["reservation_created"] reserved_arguments["reservation_error"] = "0" all_arguments = {} all_arguments.update( reserved_arguments ) all_arguments.update( filtered_kwargs ) uuid = uuid4().hex logger.debug( "Creating reservation on SimpleDB for %s, %s." % (function_name, uuid)) a = self.sdb.putAttributes( self.aws_sdb_reservation_domain, uuid, all_arguments ) a.addCallback( self._createReservationCallback, function_name, uuid ) a.addErrback( self._createReservationErrback, function_name, uuid ) if "call_immediately" in kwargs and not evaluateBoolean( kwargs["call_immediately"] ): d = DeferredList([a], consumeErrors=True) else: logger.debug( "Calling %s immediately with arguments:\n%s" % (function_name, PrettyPrinter.pformat(filtered_kwargs) ) ) b = self.callExposedFunctionImmediately( function["function"], filtered_kwargs, function_name ) d = DeferredList([a,b], consumeErrors=True) d.addCallback( self._createReservationCallback2, function_name, uuid ) d.addErrback( self._createReservationErrback2, function_name, uuid ) return d else: logger.debug( "Calling %s immediately with arguments:\n%s" % (function_name, PrettyPrinter.pformat(filtered_kwargs) ) ) d = self.callExposedFunctionImmediately( function["function"], filtered_kwargs, function_name ) return d
def getServerData( self ): running_time = time.time() - self.start_time cost = (self.sdb.box_usage * .14) * (60*60*24*30.4) / (running_time) active_requests_by_host = self.rq.getActiveRequestsByHost() pending_requests_by_host = self.rq.getPendingRequestsByHost() data = { "paused":self.paused, "running_time":running_time, "cost":cost, "active_requests_by_host":active_requests_by_host, "pending_requests_by_host":pending_requests_by_host, "active_requests":self.rq.getActive(), "pending_requests":self.rq.getPending(), "current_timestamp":sdb_now(offset=self.time_offset) } logger.debug("Got server data:\n%s" % PrettyPrinter.pformat(data) ) return data
def query( self, data=None ): if self.uuid_limits["start"] is None and self.uuid_limits["end"] is not None: uuid_limit_clause = "AND itemName() < '%s'" % self.uuid_limits["end"] elif self.uuid_limits["start"] is not None and self.uuid_limits["end"] is None: uuid_limit_clause = "AND itemName() > '%s'" % self.uuid_limits["start"] elif self.uuid_limits["start"] is None and self.uuid_limits["end"] is None: uuid_limit_clause = "" else: uuid_limit_clause = "AND itemName() BETWEEN '%s' AND '%s'" % (self.uuid_limits["start"], self.uuid_limits["end"]) sql = """SELECT itemName() FROM `%s` WHERE reservation_next_request < '%s' %s LIMIT %s """ % (self.aws_sdb_reservation_domain, sdb_now(offset=self.time_offset), uuid_limit_clause, self.job_limit) #INTERSECTION reservation_error != '1' logger.debug( "Querying SimpleDB, \"%s\"" % sql ) d = self.sdb.select( sql ) d.addCallback( self._queryCallback ) d.addErrback( self._queryErrback )