/* --------------------------------------------------------------------------- $Revision: 1.1.2.7.2.1 $ $Date: 2017/01/11 13:02:06 $ NAME: cxt_get_etl_settings.sas TYPE: cmacro DESCRIPTION: SAS VERSION: 9.4 INPUT: OUTPUT: CALLS: CALLED BY (optional): PRECONDITIONS (optional): POSTCONDITIONS (optional): HISTORY: userid yyyymmdd defectid desc sinshd 20140808 ------------------------------------------------------------------------------ Copyright (c) 2005-2015, SAS Institute Inc., Cary, NC, USA, All Rights Reserved ------------------------------------------------------------------------------ */ %macro cxt_get_etl_settings ; %******************************************************************************; %* Get ETL Settings from ACS ; %******************************************************************************; %* Define filenames ; %let headerin=hdrin ; %let headerout=hdrout ; %let outfile= profile; filename &headerin temp; filename &headerout temp; filename &outfile temp; %* Create PUT request header file ; data _null_; file hdrin encoding="utf-8" recfm=f lrecl=1; /*put 'Accept: application/xml';*/ put 'Accept: application/vnd.sas.marketing.acs.normalization.profile+xml'; putlog 'Accept: application/vnd.sas.marketing.acs.normalization.profile+xml'; run; %let requestMethod=%nrquote(GET); /*%let requestCT =%nrquote(application/json);*/ %let requestCT =%nrquote(application/vnd.sas.marketing.acs.normalization.profile+json); %let requestURL = %nrquote(%sysfunc(trim(&ACS_ADMIN_GET_URL.))); %let service_auth=%nrquote(&ACS_SERVICE_AUTH); %let proxy_host=%nrquote(&proxy_host); %let proxy_port=%nrquote(&proxy_port); %let proxy_auth=%nrquote(&proxy_auth); %let RetryAttemptNo=0; %HTTPTRYAGAIN: %* call PROC HTTTP PUT method ; %cxt_HTTPRequest(outfile=&outfile, headerin=&headerin, headerout=&headerout, requestCT=&requestCT, requestURL=&requestURL, requestMethod=&requestMethod, service_auth=&service_auth, proxy_host=&proxy_host, proxy_port=&proxy_port, proxy_auth=&proxy_auth ); %if &retcode=1 %then %do; %cxt_echofile_tolog(fileRefs=&headerin &headerout &outfile); /*%goto ERROREXIT;*/ %goto HTTPERROR; %end; %* set the GET ETL Settings Map file name ; data _null_; settingsMapfile =strip(symget('cxtcnfg_libPath')) || '/GetProfile.map'; call symput('ETLSettingsMapfile', strip(settingsMapfile) ); run; %* check if the statusMap file exists else create it ; %if %sysfunc(fileexist(&ETLSettingsMapfile)) eq 0 %then %do; %cxt_MakeStatusMapFile(mapName=&ETLSettingsMapfile); %end; %* Read the GET Settings outout file to get the sas timestamps ; filename profMap "&ETLSettingsMapfile"; libname &outfile xmlv2 xmlmap=profMap; %* When PROC HTTP PUT is successful then read the header out file to check the status of the execution; %cxt_HTTPReadHeader(Action=ACS_GET_SETTINGS,hdrout=&headerout); %if &retcode=1 %then %do; %cxt_echofile_tolog(fileRefs=&headerin &headerout &outfile); /*%goto ERROREXIT;*/ %goto HTTPERROR; %end; %* read ETL settings dataset from the response file generated by Admin Settings GET request; proc copy in=&outfile out=work; run; %* check if there are errors in reading the response file ; %if &SYSERR. > 4 %then %do; %*write the files to log ; %cxt_echofile_tolog(fileRefs=&headerin &headerout &outfile); %* do a retry attempt ; %goto HTTPERROR; %end; %* check if Etlprofile is returned ; %if %cxt_get_observation_count(indsn=Etlprofile) = 0 %then %do; %let retcode=1; %let typemsg = %sysfunc(sasmsg(&msg_dset,_cxaerrmsg_label,noquote)); %let errmsg=%sysfunc(sasmsg(&msg_dset,_cxa_norm_16_err,noquote,ACS_GET_SETTINGS)); %goto ERROREXIT;; %end; %* Read the ETL Settings from work dataset and create admin options dataset & round the start & end ts to 000 & 999 milliseconds resp. ; data cxt_etl_admin_options; format st et datetime27.6; format event_start_dttm event_end_dttm 30.; merge Etlprofile Reprocessprofile; /* set start and end ts = javaTs/1000 - 1 second */ st=event_Start_dttm/1000 - 1; et=event_end_dttm/1000 - 1; /* re-assign the start by rounding it and converting back to milliseconds this will make sure that start is always 000 millisecods */ event_start_dttm=round(st,1) * 1000; /* re-assign the end by rounding it and converting back to milliseconds this will make sure that end is always 999 millisecods */ event_end_dttm=round(et,1) * 1000 + 999 ; /* when AUTO_REPROCESS = YES then set SQL_DEL_FILE to missing */ if upcase(AUTO_REPROCESS)='YES' then SQL_DEL_FILE=''; drop st et; run; %goto HTTPSUCCESS; /* on http errors retry http call */ %HTTPERROR: /* if retry attempts are left then try again */ %if &RetryAttemptNo. < &CXT_HTTP_MAX_RETRY_ATTEMPTS. %then %do; /* reset retcode */ %let retcode=0; %* reset errors 1. reset syserr 2. reset syscc 3. Reset SYNTAXCHECK OBS REPLACE DMSSYNCHK options - added for proc copy failure errors ; data _null_; run; %let syscc=0; OPTIONS OBS=MAX REPLACE NOSYNTAXCHECK NODMSSYNCHK; /*increment RetryAttemptNo */ %let RetryAttemptNo=%sysevalf(&RetryAttemptNo + 1); /* do some rest */ data _null_; call sleep(&CXT_HTTP_RETRY_WAIT_SEC.,1); run; %let msgtype = %sysfunc(sasmsg(&msg_dset,_cxanotemsg_label,noquote)); %let msgdesc = %sysfunc(sasmsg(&msg_dset,_cxa_norm_20_note,noquote,&RetryAttemptNo.)); %put &msgtype. &msgdesc.; %goto HTTPTRYAGAIN; %end; %HTTPSUCCESS: %ERROREXIT: %mend;