Exemplo n.º 1
0
def _transfer(config, container, products_dir, cancel=False):
    # extract the info.json object from the container
    info = container.getDictionary('info.json')
    properties, product_properties = _get_properties(info)

    # get the config information:
    for transfer_method, transfer_dict in config.items():
        logging.debug('Doing %s transfers...' % transfer_method)
        for destination, params in transfer_dict.items():
            params.update(properties)
            fmt = 'Doing %s transfer to %s...'
            tpl = (transfer_method, destination)
            logging.debug(fmt % tpl)
            # append eventid to remote_directory, if present
            if 'remote_directory' in params:
                rem_dir = params['remote_directory']
                params['remote_directory'] = os.path.join(
                    rem_dir, params['code'])

            # get the sender class from the type
            sender_class = get_sender_class(transfer_method)

            # try to send the data
            try:
                if transfer_method == 'pdl':
                    sender = sender_class(
                        properties=params,
                        local_directory=products_dir,
                        product_properties=product_properties)
                else:
                    cancelfile = CANCEL_FILES[transfer_method]
                    sender = sender_class(properties=params,
                                          local_directory=products_dir,
                                          cancelfile=cancelfile)

                if cancel:
                    msg = sender.cancel()
                else:
                    nfiles, msg = sender.send()
                fmt = '%i files sent.  Message from sender: \n"%s"'
                tpl = (nfiles, msg)
                logging.info(fmt % tpl)
            except Exception as e:
                # for the standard config, this should generate an email to
                # the developer list.
                msg = str(e)
                fmt = ('Transfer for %s method, %s destination '
                       'failed with error "%s".')
                tpl = (transfer_method, destination, msg)
                logging.warning(fmt % tpl)
                continue
Exemplo n.º 2
0
def transfer(config,pagerdata,authid,authsource,version_folder,renotify=False,release=False):
    #If system status is primary and transfer options are configured, transfer the output
    #directories using those options
    res = False
    msg = ''
    if 'status' in config and config['status'] == 'primary':
        if 'transfer' in config:
            if 'methods' in config['transfer']:
                print('Running transfer.')
                for method in config['transfer']['methods']:
                    if method not in config['transfer']:
                        sys.stderr.write('Method %s requested but not configured...Skipping.' % method)
                        continue
                    params = config['transfer'][method]
                    if 'remote_directory' in params:
                        vpath,vfolder = os.path.split(version_folder)
                        #append the event id and version folder to our pre-specified output directory
                        params['remote_directory'] = os.path.join(params['remote_directory'],authid,vfolder)
                    params['code'] = authid
                    params['eventsource'] = authsource
                    params['eventsourcecode'] = authid.replace(authsource,'')
                    params['magnitude'] = pagerdata.magnitude
                    params['latitude'] = pagerdata.latitude
                    params['longitude'] = pagerdata.longitude
                    params['depth'] = pagerdata.depth
                    params['eventtime'] = pagerdata.time
                    product_params = {'maxmmi':pagerdata.maxmmi,
                                      'alertlevel':pagerdata.summary_alert_pending}

                    if renotify:
                        product_params['renotify'] = 'true'
                    if release:
                        product_params['release'] = 'true'
                    sender_class = get_sender_class(method)
                    try:
                        if method == 'pdl':
                            sender = sender_class(properties=params,local_directory=version_folder,
                                                  product_properties=product_params)
                        else:
                            sender = sender_class(properties=params,local_directory=version_folder)
                        try:
                            nfiles,msg = sender.send()
                            res = True
                        except Exception as e:
                            msg = str(e)
                            res = False
                    except Exception as e:
                        msg = str(e)
                        res = False
                        continue
    return (res,msg)
def test():
    print('Testing basic file system copy...')
    thisfile = os.path.abspath(__file__)
    tempdir = tempfile.mkdtemp()
    try:
        sender_class = get_sender_class('copy')
        cpsender = sender_class(properties={'remote_directory': tempdir},
                                local_files=[thisfile])
        nfiles = cpsender.send()
        nfiles = cpsender.cancel()
    except Exception as obj:
        raise SenderError('Failed to copy or delete a file.')
    shutil.rmtree(tempdir)
    print('Passed basic file system copy.')
Exemplo n.º 4
0
def transfer(config, pagerdata, authid, authsource, version_folder,
             renotify=False, release=False, force_email=False,
             is_scenario=False):
    """Call all relevant transfer methods specified in config.

    :param config:
      Dictionary containing PAGER configuration information (from config.yml file).
    :param pagerdata:
      PagerData object.
    :param authid:
      Authoritative event ID.
    :param authsource:
      Authoritative event source.
    :param version_folder:
      Folder where PAGER version information is stored.
    :param renotify:
      Boolean indicating whether a renotify flag should be sent through to PAGER email process.
    :param release:
      Boolean indicating whether a release flag should be sent through to PAGER email process.
    :param force_email:
      Boolean indicating whether a force_email flag should be sent through to PAGER email process.
    :returns:
      Tuple of:
        - Boolean result indicating overall success or failure of transfer.
        - String message from transfer send() method.
    """
    # If system status is primary and transfer options are configured, transfer the output
    # directories using those options
    res = False
    msg = ''
    if 'status' in config and config['status'] == 'secondary': 
      res = True
      return (res, msg)
    if 'status' in config and config['status'] == 'primary':
        if 'transfer' in config:
            if 'methods' in config['transfer']:
                logging.info('Running transfer.')
                for method in config['transfer']['methods']:
                    if method not in config['transfer']:
                        sys.stderr.write(
                            'Method %s requested but not configured...Skipping.' % method)
                        continue
                    params = config['transfer'][method]
                    if is_scenario:
                        params['type'] = 'losspager-scenario'
                    if renotify:
                        params['type'] = 'losspager-admin'
                    if 'remote_directory' in params:
                        vpath, vfolder = os.path.split(version_folder)
                        # append the event id and version folder to our pre-specified output directory
                        params['remote_directory'] = os.path.join(
                            params['remote_directory'], authid, vfolder)
                    params['code'] = authid
                    params['eventsource'] = authsource
                    params['eventsourcecode'] = authid.replace(authsource, '')
                    params['magnitude'] = pagerdata.magnitude
                    params['latitude'] = pagerdata.latitude
                    params['longitude'] = pagerdata.longitude
                    params['depth'] = pagerdata.depth
                    params['eventtime'] = pagerdata.time
                    product_params = {'maxmmi': pagerdata.maxmmi,
                                      'review-status': STATUSDICT[release],
                                      'alertlevel': pagerdata.summary_alert_pending}

                    if renotify:
                        product_params['renotify'] = 'true'
                    if release:
                        product_params['release'] = 'true'
                    if force_email:
                        product_params['force-email'] = 'true'
                    sender_class = get_sender_class(method)
                    try:
                        if method == 'pdl':
                            sender = sender_class(properties=params, local_directory=version_folder,
                                                  product_properties=product_params)
                        else:
                            sender = sender_class(
                                properties=params, local_directory=version_folder)
                        try:
                            nfiles, msg = sender.send()
                            res = True
                        except Exception as e:
                            msg = str(e)
                            res = False
                    except Exception as e:
                        msg = str(e)
                        res = False
                        continue
    return (res, msg)