Script Groovy

Se le password contengono caratteri speciali, fare riferimento alla sezione Gestione dei caratteri speciali. Assicurarsi inoltre di sostituire i valori dei parametri elencati di seguito a seconda degli ambienti.

Table 3-13 Parametri da modificare

Parametro Descrizione
user Nome utente di un amministratore del servizio.
password Password dell'Amministratore servizi o nome e posizione del password file cifrato.
url URL dell'ambiente in cui si desidera impostare la cadenza di aggiornamento non mensile.
updatemonths Applicare un elenco separato da virgole con i mesi in cui viene aggiornato Oracle Enterprise Performance Management Cloud all'ambiente identificato dal parametro url. Ad esempio, updatemonths=02,05,08,11.

I mesi devono essere specificati con due cifre: da 01 per gennaio fino a 12 per dicembre. Assicurarsi di anteporre uno zero per i mesi da gennaio a settembre. Lo script tenta di eseguire il comando skipUpdate per i mesi non inclusi nel valore del parametro updatemonths. Se ad esempio si specifica updatemonths=02,05,08,11, lo script tenta di impostare i flag per saltare gli aggiornamenti per gennaio, marzo, aprile, giugno, luglio, settembre, ottobre e dicembre in modo che gli aggiornamenti vengano eseguiti solo a febbraio, maggio, agosto e novembre.

import java.text.SimpleDateFormat

String user = 'service_administrator'
String password = 'examplePWD'
String url = 'example_EPM_URL'
String updatemonths = '02,05,08,11'

def currentdate = new Date()
def yf = new SimpleDateFormat("yy")
def mf = new SimpleDateFormat("MM")
String[] monthsarr = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
List<String> monthsarrfromcurrent = new ArrayList<>()
List<String> yearsarrfromcurrent = new ArrayList<>()
String currentyear = yf.format(currentdate)
String nextyear = (currentyear.toInteger() + 1).toString()
String currentmonth = mf.format(currentdate)

String[] updateMonthsStringArr = updatemonths.split(',');
def updatemonthsarr = new int[updateMonthsStringArr.length];
for(int i = 0; i < updateMonthsStringArr.length; i++)
{
    updatemonthsarr[i] = Integer.parseInt(updateMonthsStringArr[i]);
}

def LogMessage(String message) {
    def date = new Date()
    def sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
    println('[' + sdf.format(date) + '][GROOVY] ' + message);
}

def LogOperationStatus(EpmAutomateStatus opstatus) {
    def returncode = opstatus.getStatus()
    if (returncode != 0){
        LogMessage(opstatus.getOutput())
    }
    LogMessage('return code: ' + returncode)
}

int CompareUpdateMonths(int thismonth, int nextmonth) {
    int nextmonthorig = nextmonth

    if (nextmonth < thismonth) {
        nextmonth = nextmonth + 12
    }

    int monthdiff = nextmonth - thismonth

    if (monthdiff > 3) {
        LogMessage('There are more than 2 months skipped from month ' + thismonth + ' to month ' + nextmonthorig + '. Please correct updatemonths so that there are not more than two months skipped between each update month. Exiting.')
        return 1
    }
    
    return 0
}

int ValidateUpdateMonths(int[] updatemonthsarr) {
    for(int i = 0; i < updatemonthsarr.length; i++)
    {
        int nextint = i + 1
        String nextupdatemonth = ""
        int nextupdatemonthint = 0
        String thisupdatemonth = updatemonthsarr[i]
        int thisupdatemonthint = thisupdatemonth.toInteger()
        
        if (nextint < updatemonthsarr.length) {
            nextupdatemonth = updatemonthsarr[nextint]
        } else {
            nextupdatemonth = updatemonthsarr[0]
        }
        
        nextupdatemonthint = nextupdatemonth.toInteger()
        
        int returncode = CompareUpdateMonths(thisupdatemonthint, nextupdatemonthint)
        if (returncode > 0) {
            return 1
        }
    }
    return 0
}

def SkipUpdateAdd(EpmAutomate automate, String yearnumber, String monthnumber) {
    String yeardotmonth = yearnumber + '.' + monthnumber
    LogMessage('Running: epmautomate skipUpdate add version=' + yeardotmonth + ' comment=\"adding skipUpdate\"')
    EpmAutomateStatus status = automate.execute('skipupdate','add','version=' + yeardotmonth,'comment=\"adding skipUpdate\"')
    LogOperationStatus(status)
}

LogMessage('Starting skip update processing')
EpmAutomate automate = getEpmAutomate()

// validate update months
int returncode = ValidateUpdateMonths(updatemonthsarr)
if (returncode != 0) {
    return 1
}

// populate arrays
int startposition = 0
for(int i = 0; i < monthsarr.length; i++)
{
    if (currentmonth == monthsarr[i]) {
        startposition = i
        break
    }
}
    
for(int i = 0; i < monthsarr.length; i++)
{
    if (i >= startposition) {
        monthsarrfromcurrent.add(monthsarr[i])
        yearsarrfromcurrent.add(currentyear)
    }
}

for(int i = 0; i < monthsarr.length; i++)
{
    if (i <= startposition) {
        monthsarrfromcurrent.add(monthsarr[i])
        yearsarrfromcurrent.add(nextyear)
    }
}

// process skip updates
LogMessage("Operation: encrypt " + password + " oracleKey password.epw")
EpmAutomateStatus status = automate.execute('encrypt',password,"oracleKey","password.epw")
LogOperationStatus(status)

LogMessage("Operation: login " + user + " password.epw " + url)
status = automate.execute('login',user,"password.epw",url)
LogOperationStatus(status)

LogMessage('Running: epmautomate skipUpdate remove')
status = automate.execute('skipupdate','remove')
LogOperationStatus(status)

int addcount = 0

for (int i = 0; i < monthsarrfromcurrent.size(); i++) {
    int match = 1
    
    if (addcount == 2){
        LogMessage('Two skip update add calls have been made. No more will be attempted.')
        break
    }
    
    for(int j = 0; j < updatemonthsarr.length; j++) {
    
        if (Integer.parseInt(monthsarrfromcurrent.get(i)) == updatemonthsarr[j]) {
            match = 0
            break
        }
    }
    
    if (match == 1) {
        SkipUpdateAdd(automate, yearsarrfromcurrent.get(i), monthsarrfromcurrent.get(i))
        addcount+=1
    }
}

LogMessage('Running: epmautomate skipUpdate list')
status = automate.execute('skipupdate','list')
LogOperationStatus(status)

LogMessage('Running: epmautomate logout')
status = automate.execute('logout')
LogOperationStatus(status)

LogMessage('Skip update processing completed')