Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
install_service.bat <work dir> <region name>

# Where 'work dir' is the directory containing the BIN, JRE and REGION dirs
# and 'region name' is the directory name of the region for which to install the service

Running the install_service.bat creates a file called bin.txt. This file contains the class path variable that needs to be inserted into the service parameter field JVM Option Number 1. This must be done using the tool 'regedit'. The reason for this complicated step is that the FEWS class path is too long causing the service install script to fail.

When in 'regedit' the installed service can be found in the location:
Computer->HKEY_LOCAL_MACHINE->SYSTEM->CurrentControlSet->services->FewsShell <pi service name>

Start and stop the new service using the Windows services application. The service will have the following name; FewsShell <region name>.

...

Code Block
#include <stdio.h>
#include <tcl.h>

/* Define some helper variables and functions */

Tcl_Interp *interp;

int main( int argc, char *argv[] ) {

    /* Get the library started */

    if ( Init( argv[0] ) != TCL_OK ) {
        fprintf( stderr, "Sorry, initialisation failed: %s\n",
            Tcl_GetStringResult( interp ) );
    }

    /* Here insert calls to Pi Service */
    fprintf( stdout, "Locations: %s\n", getLocations( "id not required" ) ); 
    fprintf( stdout, "New task: %s\n", createTask( "id not required" ) );
}

void TearDown () {Tcl_Finalize();}

int EvalFile (char *fileName) {
    return Tcl_EvalFile(interp, fileName);
}

int Init (char *argv0) {
    char *pchar;
    char  buffer[1000];

    /* Initialise the library itself */

    Tcl_FindExecutable(argv0);
    interp = Tcl_CreateInterp();
    if (Tcl_Init(interp) != TCL_OK) {
        return TCL_ERROR;
    }

    /* Initialise the FEWS PI services */

    strcpy( buffer, argv0 );
    pchar = strrchr( buffer, '/' );
    if ( pchar == NULL ) {
        pchar = strrchr( buffer, '\\' );
    }
    if ( pchar == NULL ) {
        pchar = buffer;
    }
    strcpy( buffer, "fewspi.tcl" );

    return EvalFile( buffer );
}

...

Code Block
   /**
     * Test the retrieval of system time.
     * <p/>
     * With this test the system time of a running Fews Region (on port 8191) can be retrieved. If the
     * system time of the region is changed then the returned value here will match the change.
     */
    public void testSystemTime() {
        String clientId = "not required";
        Date date = serviceProxy.getSystemTime(clientId);


        System.out.println("Current System time : " + dateFormat.format(date));
    }

    /**
     * Return the warm state times from the data base for the configured moduleState id=RSNWELEV_DETO3I
     * in the service configuration file = TestConfig.
     */
    public void testGetWarmStateTimes() {
        //name of service config file
        String clientId = "TestConfig";
        //id of moduleState element
        String moduleId = "RSNWELEV_DETO3I";

        Date[] stateTimes = serviceProxy.getAvailableStateTimes(clientId, moduleId);

        System.out.println("State times for Module " + moduleId);
        for (Date stateTime : stateTimes) {
            System.out.println("time: " + dateFormat.format(stateTime));
        }
    }

    /**
     * Return the cold state ids from the data base for the configured moduleState id=RSNWELEV_DETO3I
     * in the service configuration file = TestConfig.
     */
    public void testGetColdStateIds() {
        //name of service config file
        String clientId = "TestConfig";
        //id of moduleState element
        String moduleId = "RSNWELEV_DETO3I";

        String[] stateIds = serviceProxy.getColdStateIds(clientId, moduleId);

        System.out.println("Cold state ids for model " + moduleId);
        for (String id : stateIds) {
            System.out.println("cold state: " + id);
        }
    }

    /**
     * Return the warm state file from the data base for the configured moduleState id=SNOW17_LSMO3U
     * in the service configuration file = TestConfig. Write file to location d:/temp/<moduleStateId>.zip
     */
    public void testGetModuleStateBinary() throws IOException {
        //name of service config file
        String clientId = "TestConfig";
        //id of moduleState element
        String moduleId = "SNOW17_LSMO3U";

        Date[] stateTimes = serviceProxy.getAvailableStateTimes(clientId, moduleId);
        byte[] binary = serviceProxy.getModuleStateBinary(clientId, moduleId, stateTimes[0], null, -1);

        ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(binary));
        try {
            ZipUtils.unzipFiles(zipInputStream, new File("d:/temp/" + moduleId + ".zip"));
        } finally {
            zipInputStream.close();
        }
    }

    /**
     * Returns the content of a client configuration file from the config directory PiClientConfigFiles.
     *
     * Only requirement is that a configuration file (any type) with the clientId as name and moduleId as extension
     * must exist in this config directory.
     */
    public void testGetClientConfigurationFile(){
        //Name of client file
        String clientId = "MyClientConfigFile";
        //extension of client file
        String moduleId = "txt";

        String clientText = serviceProxy.getClientConfigFile(clientId, moduleId);

        System.out.println("Client file content: " + clientText);

    }

    /**
     * Retrieve the content of the locations xml. Write this to d:/temp/locations.xml
     * @throws IOException
     */
    public void testGetLocations() throws IOException {

        String locations = serviceProxy.getLocations("id not required");

        System.out.println("Content of locations xml file: " + locations);
        FileUtils.writeText("d:/temp/locations.xml", IOUtils.UTF8_CHARSET, locations);

    }

    /**
     * Return the member indices for the ensemble id = "ESP" from the timeseries table.
     *
     * This only works when there are ensemble members in the TimeSeries table.
     */
    public void testGetEnsembleMemberIndices(){

        String ensembleId = "ESP";
        int[] indices = serviceProxy.getEnsembleMemberIndices("id not required", ensembleId);

        System.out.println("Ensemble id " + ensembleId + " contains " + indices.length + " members.");
        System.out.println("indices are: ");
        for (int indice : indices) {
            System.out.println(indice);
        }

    }

    /**
     * Get the logentries for an Import TaskId.
     *
     * Check the LogEntries table to find a matching taskId.
     * 
     * @throws IOException
     */
    public void testGetLogInformation() throws IOException {

        String taskId = "NWSNWMC00:0000026"; //=import
        String logInfo = serviceProxy.getLogMessages("id not required", taskId);

        System.out.println("Content of log: " + logInfo);
        FileUtils.writeText("d:/temp/log.xml", IOUtils.UTF8_CHARSET, logInfo);

    }

    /**
     * Return the timeseries defined in the service configuration file under timeSeries element with id 'Reservoir'.
     *
     * Filter using parameter ids QIN and RQIN and location ids DETO3, GPRO3 and FOSO3
     *
     * Check timeseries table to look for existing times for these timeseries.
     *
     * @throws IOException
     */
    public void testGetTimeSeries() throws IOException {

        Date systemTime = serviceProxy.getSystemTime("id not required");
        Calendar instance = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
        instance.set(2009, 4, 1);
        Date start = instance.getTime();
        instance.set(2009, 4, 11);
        Date end = instance.getTime();
        String[] params = new String[]{"QIN", "RQIN"};
        String[] locs = new String[]{"DETO3","GPRO3","FOSO3"};
        String headers = serviceProxy.getTimeSeriesHeaders("TestConfig", "Reservoir", null, start, systemTime, end, params, locs, null, -1);

        System.out.println("Content of tineseries headers: " + headers);

        String timeseriesfile = serviceProxy.getTimeSeries("TestConfig", "Reservoir", null, start, systemTime, end, params, locs, null, -1);

        FileUtils.writeText("d:/temp/timeseries.xml", IOUtils.UTF8_CHARSET, timeseriesfile);

    }

    /**
     * Upload a pi_diag log file to the region.
     *
     * Make sure to create an input file in corresponding directory.
     *
     * @throws IOException
     */
    public void testInsertLogMessages() throws IOException {

        String logText = FileUtils.readText("d:/temp/inputlog.xml");
        serviceProxy.putLogMessage("used as description", logText);
    }

    /**
     * Upload a pi_timeseries file to the Region. The timeseries in this file must be linked to timeseries configured
     * in the PiServiceConfig file.
     *
     * Make sure to create an input file in the corresponding directory.
     *
     * @throws IOException
     */
    public void testInsertTimeSeries() throws IOException {

        String timeseriesText = FileUtils.readText("d:/temp/inputtimeseries.xml");
        System.out.println("Input timeseries: " + timeseriesText);
        serviceProxy.putTimeSeries("TestConfig", null, "Reservoir", timeseriesText, null, -1);
    }

    /**
     * Schedule a task run and wait for it to finish.
     * 
     */
    public void testRunningTask(){
        String taskId = serviceProxy.createTask("id not required");
        Date date = serviceProxy.getSystemTime("");
        System.out.println("Starting task with id " + taskId + " time=" + new Date(System.currentTimeMillis()));
        String taskRunId = serviceProxy.runTask("id not required", taskId, "Santiam_Forecast", date, date, date, null, null, "Test user", "PiWebservice taskrun");

        boolean result = serviceProxy.waitForTask("id not required", taskRunId, 120000);
        System.out.println("Task with id " + taskId + (result ? " finished successfully" : " failed"));
        System.out.println("time=" + new Date(System.currentTimeMillis()));
    }

...