Пример #1
0
 def make_reservation(self):
     """Perform a reservation of the required number of nodes"""
     logger.info('Performing reservation')
     starttime = int(time.time() +
                     timedelta_to_seconds(datetime.timedelta(minutes=1)))
     endtime = int(
         starttime +
         timedelta_to_seconds(datetime.timedelta(days=3, minutes=1)))
     startdate, n_nodes = self._get_nodes(starttime, endtime)
     while not n_nodes:
         logger.info('No enough nodes found between %s and %s, ' + \
                     'increasing time window',
                     format_date(starttime), format_date(endtime))
         starttime = endtime
         endtime = int(
             starttime +
             timedelta_to_seconds(datetime.timedelta(days=3, minutes=1)))
         startdate, n_nodes = self._get_nodes(starttime, endtime)
         if starttime > int(time.time() +
                            timedelta_to_seconds(datetime.timedelta(
                                weeks=6))):
             logger.error('There are not enough nodes on %s for your ' + \
                          'experiments, abort ...', self.cluster)
             exit()
     jobs_specs = get_jobs_specs({self.cluster: n_nodes},
                                 name=self.__class__.__name__)
     sub = jobs_specs[0][0]
     sub.walltime = self.options.walltime
     sub.additional_options = '-t deploy'
     sub.reservation_date = startdate
     (self.oar_job_id, self.frontend) = oarsub(jobs_specs)[0]
     logger.info('Startdate: %s, n_nodes: %s', format_date(startdate),
                 str(n_nodes))
Пример #2
0
 def make_reservation(self):
     """Perform a reservation of the required number of nodes"""
     logger.info('Performing reservation')
     starttime = int(time.time() + timedelta_to_seconds(datetime.timedelta(minutes=1)))
     endtime = int(starttime + timedelta_to_seconds(datetime.timedelta(days=3,
                                                              minutes=1)))
     startdate, n_nodes = self._get_nodes(starttime, endtime)
     while not n_nodes:
         logger.info('No enough nodes found between %s and %s, ' + \
                     'increasing time window',
                     format_date(starttime), format_date(endtime))
         starttime = endtime
         endtime = int(starttime + timedelta_to_seconds(datetime.timedelta(days=3,
                                                             minutes=1)))
         startdate, n_nodes = self._get_nodes(starttime, endtime)
         if starttime > int(time.time() + timedelta_to_seconds(
                                         datetime.timedelta(weeks=6))):
             logger.error('There are not enough nodes on %s for your ' + \
                          'experiments, abort ...', self.cluster)
             exit()
     jobs_specs = get_jobs_specs({self.cluster: n_nodes},
                                 name=self.__class__.__name__)
     sub = jobs_specs[0][0]
     sub.walltime = self.options.walltime
     sub.additional_options = '-t deploy'
     sub.reservation_date = startdate
     (self.oar_job_id, self.frontend) = oarsub(jobs_specs)[0]
     logger.info('Startdate: %s, n_nodes: %s', format_date(startdate),
                 str(n_nodes))
Пример #3
0
def find_coorm_slot(slots, resources_wanted):
    """ """
    for start, stop, res in slots:
        logger.debug("%s %s %s" % (format_date(start), format_date(stop), res))
        slot_ok = True
        for element, cpu in resources_wanted.items():
            logger.debug("%s %s" % (element, cpu))
            if res[element] < cpu * (stop - start) / 3600:
                slot_ok = False
        if slot_ok:
            return start, stop, res
Пример #4
0
 def __repr__(self):
     s = ""
     if self.resources != None:
         s = comma_join(s, "resources=%r" % (self.resources, ))
     if self.walltime != None:
         s = comma_join(s,
                        "walltime=%r" % (format_duration(self.walltime), ))
     if self.job_type != None:
         s = comma_join(s, "job_type=%r" % (self.job_type, ))
     if self.sql_properties != None:
         s = comma_join(s, "sql_properties=%r" % (self.sql_properties, ))
     if self.queue != None: s = comma_join(s, "queue=%r" % (self.queue, ))
     if self.reservation_date != None:
         s = comma_join(
             s,
             "reservation_date=%r" % (format_date(self.reservation_date), ))
     if self.directory != None:
         s = comma_join(s, "directory=%r" % (self.directory, ))
     if self.project != None:
         s = comma_join(s, "project=%r" % (self.project, ))
     if self.name != None: s = comma_join(s, "name=%r" % (self.name, ))
     if self.additional_options != None:
         s = comma_join(
             s, "additional_options=%r" % (self.additional_options, ))
     if self.command != None:
         s = comma_join(s, "command=%r" % (self.command, ))
     return "OarSubmission(%s)" % (s, )
Пример #5
0
    def make_reservation(self):
        """Perform a reservation of the required number of nodes."""

        logger.info('Performing reservation')
        now = int(time.time() +
                  timedelta_to_seconds(datetime.timedelta(minutes=1)))
        starttime = now
        endtime = int(
            starttime +
            timedelta_to_seconds(datetime.timedelta(days=3, minutes=1)))
        startdate, n_nodes = self._get_nodes(starttime, endtime)

        search_time = 3 * 24 * 60 * 60  # 3 days
        walltime_seconds = get_seconds(self.options.walltime)

        iteration = 0
        while not n_nodes:
            iteration += 1
            logger.info(
                'Not enough nodes found between %s and %s, ' +
                'increasing time window', format_date(starttime),
                format_date(endtime))
            starttime = max(now,
                            now + iteration * search_time - walltime_seconds)
            endtime = int(now + (iteration + 1) * search_time)

            startdate, n_nodes = self._get_nodes(starttime, endtime)
            if starttime > int(time.time() +
                               timedelta_to_seconds(datetime.timedelta(
                                   weeks=6))):
                logger.error(
                    'There are not enough nodes on %s for your ' +
                    'experiments, abort ...', self.cluster)
                exit()

        jobs_specs = get_jobs_specs({self.cluster: n_nodes},
                                    name=self.__class__.__name__)
        sub = jobs_specs[0][0]
        sub.walltime = self.options.walltime
        if self.use_kadeploy:
            sub.additional_options = '-t deploy'
        else:
            sub.additional_options = '-t allow_classic_ssh'
        sub.reservation_date = startdate
        (self.oar_job_id, self.frontend) = oarsub(jobs_specs)[0]
        logger.info('Startdate: %s, n_nodes: %s, job_id: %s',
                    format_date(startdate), str(n_nodes), str(self.oar_job_id))
Пример #6
0
    def make_reservation(self):
        """Perform a reservation of the required number of nodes."""

        logger.info('Performing reservation')
        now = int(time.time() +
                  timedelta_to_seconds(datetime.timedelta(minutes=1)))
        starttime = now
        endtime = int(starttime +
                      timedelta_to_seconds(datetime.timedelta(days=3,
                                                              minutes=1)))
        startdate, n_nodes = self._get_nodes(starttime, endtime)

        search_time = 3 * 24 * 60 * 60  # 3 days
        walltime_seconds = get_seconds(self.options.walltime)

        iteration = 0
        while not n_nodes:
            iteration += 1
            logger.info('Not enough nodes found between %s and %s, ' +
                        'increasing time window',
                        format_date(starttime), format_date(endtime))
            starttime = max(now, now +
                            iteration * search_time - walltime_seconds)
            endtime = int(now + (iteration + 1) * search_time)

            startdate, n_nodes = self._get_nodes(starttime, endtime)
            if starttime > int(time.time() + timedelta_to_seconds(
                    datetime.timedelta(weeks=6))):
                logger.error('There are not enough nodes on %s for your ' +
                             'experiments, abort ...', self.cluster)
                exit()

        jobs_specs = get_jobs_specs({self.cluster: n_nodes},
                                    name=self.__class__.__name__)
        sub = jobs_specs[0][0]
        sub.walltime = self.options.walltime
        if self.use_kadeploy:
            sub.additional_options = '-t deploy'
        else:
            sub.additional_options = '-t allow_classic_ssh'
        sub.reservation_date = startdate
        (self.oar_job_id, self.frontend) = oarsub(jobs_specs)[0]
        logger.info('Startdate: %s, n_nodes: %s, job_id: %s',
                    format_date(startdate),
                    str(n_nodes), str(self.oar_job_id))
Пример #7
0
 def __repr__(self):
     s = ""
     if self.resources != None: s = comma_join(s, "resources=%r" % (self.resources,))
     if self.walltime != None: s = comma_join(s, "walltime=%r" % (format_duration(self.walltime),))
     if self.job_type != None: s = comma_join(s, "job_type=%r" % (self.job_type,))
     if self.sql_properties != None: s = comma_join(s, "sql_properties=%r" % (self.sql_properties,))
     if self.queue != None: s = comma_join(s, "queue=%r" % (self.queue,))
     if self.reservation_date != None: s = comma_join(s, "reservation_date=%r" % (format_date(self.reservation_date),))
     if self.directory != None: s = comma_join(s, "directory=%r" % (self.directory,))
     if self.project != None: s = comma_join(s, "project=%r" % (self.project,))
     if self.name != None: s = comma_join(s, "name=%r" % (self.name,))
     if self.additional_options != None: s = comma_join(s, "additional_options=%r" % (self.additional_options,))
     if self.command != None: s = comma_join(s, "command=%r" % (self.command,))
     return "OarSubmission(%s)" % (s,)
Пример #8
0
def draw_slots(slots, colors=None, show=False, save=True, outfile=None):
    """Draw the number of nodes available for the clusters (requires Matplotlib >= 1.2.0)

    :param slots: a list of slot, as returned by ``compute_slots``

    :param colors: a dict to define element coloring ``{'element': (255., 122., 122.)}``

    :param show: display the slots versus time

    :param save: save the plot to outfile

    :param outfile: specify the output file"""

    startstamp = slots[0][0]
    endstamp = slots[-1][1]
    if outfile is None:
        outfile = 'slots_' + format_date(startstamp)

    logger.info('Saving slots diagram to %s', style.emph(outfile))

    if colors is None:
        colors = _set_colors()

    xfmt = MD.DateFormatter('%d %b, %H:%M ')

    if endstamp - startstamp <= timedelta_to_seconds(timedelta(days=7)):
        x_major_locator = MD.HourLocator(byhour=[9, 19])
    elif endstamp - startstamp <= timedelta_to_seconds(timedelta(days=17)):
        x_major_locator = MD.HourLocator(byhour=[9])
    else:
        x_major_locator = MD.AutoDateLocator()

    max_nodes = {}
    total_nodes = 0
    slot_limits = []
    total_list = []
    i_slot = 0
    for slot in slots:
        slot_limits.append(slot[0])
        if i_slot + 1 < len(slots):
            slot_limits.append(slots[i_slot + 1][0])
            i_slot += 1

        for element, n_nodes in slot[2].items():
            if element in get_g5k_clusters(queues=None):
                if not element in max_nodes:
                    max_nodes[element] = []
                max_nodes[element].append(n_nodes)
                max_nodes[element].append(n_nodes)
            if element == 'grid5000':
                total_list.append(n_nodes)
                total_list.append(n_nodes)
                if n_nodes > total_nodes:
                    total_nodes = n_nodes

    slot_limits.append(endstamp)
    slot_limits.sort()

    dates = [unixts_to_datetime(ts) for ts in slot_limits]

    datenums = MD.date2num(dates)

    fig = PLT.figure(figsize=(15, 10), dpi=80)

    ax = PLT.subplot(111)
    ax.xaxis_date()
    box = ax.get_position()
    ax.set_position([box.x0 - 0.07, box.y0, box.width, box.height])
    ax.set_xlim(unixts_to_datetime(startstamp), unixts_to_datetime(endstamp))
    ax.set_xlabel('Time')
    ax.set_ylabel('Nodes available')
    ax.set_ylim(0, total_nodes * 1.1)
    ax.axhline(y=total_nodes,
               color='#000000',
               linestyle='-',
               linewidth=2,
               label='ABSOLUTE MAXIMUM')
    ax.yaxis.grid(color='gray', linestyle='dashed')
    ax.xaxis.set_major_formatter(xfmt)
    ax.xaxis.set_major_locator(x_major_locator)
    PLT.xticks(rotation=15)

    max_nodes_list = []

    p_legend = []
    p_rects = []
    p_colors = []
    for key, value in sorted(max_nodes.items()):
        if key != 'grid5000':
            max_nodes_list.append(value)
            p_legend.append(key)
            p_rects.append(PLT.Rectangle((0, 0), 1, 1, fc=colors[key]))
            p_colors.append(colors[key])

    plots = PLT.stackplot(datenums, max_nodes_list, colors=p_colors)
    PLT.legend(p_rects,
               p_legend,
               loc='center right',
               ncol=1,
               shadow=True,
               bbox_to_anchor=(1.2, 0.5))

    if show:
        PLT.show()
    if save:
        logger.debug('Saving file %s ...', outfile)
        PLT.savefig(outfile, dpi=300)
Пример #9
0
def draw_gantt(planning, colors=None, show=False, save=True, outfile=None):
    """ Draw the hosts planning for the elements you ask (requires Matplotlib)

    :param planning: the dict of elements planning

    :param colors: a dict to define element coloring ``{'element': (255., 122., 122.)}``

    :param show: display the Gantt diagram

    :param save: save the Gantt diagram to outfile

    :param outfile: specify the output file"""

    if colors is None:
        colors = _set_colors()

    n_sites = len(planning)
    startstamp = None
    endstamp = None

    for clusters_hosts in planning.values():
        for hosts_kinds in clusters_hosts.values():
            for kinds_slots in hosts_kinds.values():
                for slots in kinds_slots.values():
                    for slot in slots:
                        if startstamp == None or slot[0] < startstamp:
                            startstamp = slot[0]
                        if endstamp == None or slot[1] > endstamp:
                            endstamp = slot[1]
            if startstamp and endstamp: break
        if startstamp and endstamp: break

    for slot in slots:
        if slot[0] < startstamp:
            startstamp = slot[0]
        if slot[1] > endstamp:
            endstamp = slot[1]

    if outfile is None:
        outfile = 'gantt_' + "_".join([site for site in planning]) \
            + '_' + format_date(startstamp)
    logger.info('Saving Gantt chart to %s', style.emph(outfile))

    n_col = 2 if n_sites > 1 else 1
    n_row = int(ceil(float(n_sites) / float(n_col)))
    x_major_locator = MD.AutoDateLocator()
    xfmt = MD.DateFormatter('%d %b, %H:%M ')

    PLT.ioff()
    fig = PLT.figure(figsize=(15, 5 * n_row), dpi=80)

    i_site = 1
    for site, clusters in planning.items():
        n_hosts = 0
        for hosts in clusters.values():
            n_hosts += len(hosts)
        if n_hosts == 0: continue
        ax = fig.add_subplot(n_row, n_col, i_site, title=site.title())
        ax.title.set_fontsize(18)
        ax.xaxis_date()
        ax.set_xlim(unixts_to_datetime(startstamp),
                    unixts_to_datetime(endstamp))
        ax.xaxis.set_major_formatter(xfmt)
        ax.xaxis.set_major_locator(x_major_locator)
        ax.xaxis.grid(color='black', linestyle='dashed')
        PLT.xticks(rotation=15)
        ax.set_ylim(0, 1)
        ax.get_yaxis().set_ticks([])
        ax.yaxis.label.set_fontsize(16)
        pos = 0.0
        inc = 1.0 / n_hosts

        ylabel = ''
        for cluster, hosts in clusters.items():
            ylabel += cluster + ' '
            i_host = 0
            for key in sorted(list(hosts),
                              key=lambda name:
                              (name.split('.', 1)[0].split('-')[0],
                               int(name.split('.', 1)[0].split('-')[1]))):
                slots = hosts[key]
                i_host += 1
                cl_colors = {'free': colors[cluster], 'busy': colors['busy']}

                for kind in cl_colors:
                    for freeslot in slots[kind]:
                        edate, bdate = [
                            MD.date2num(item)
                            for item in (unixts_to_datetime(freeslot[1]),
                                         unixts_to_datetime(freeslot[0]))
                        ]
                        ax.barh(pos,
                                edate - bdate,
                                1,
                                left=bdate,
                                color=cl_colors[kind],
                                edgecolor='none')
                pos += inc
                if i_host == len(hosts):
                    ax.axhline(y=pos,
                               color=cl_colors['busy'],
                               linestyle='-',
                               linewidth=1)
        ax.set_ylabel(ylabel)
        i_site += 1
    fig.tight_layout()

    if show:
        PLT.show()
    if save:
        logger.debug('Saving file %s ...', outfile)
        PLT.savefig(outfile, dpi=300)