|
@@ -0,0 +1,188 @@
|
|
|
|
+<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
|
|
|
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
|
|
|
|
+<sect1 id="HPCC4J_Use">
|
|
|
|
+ <title>Casos de Usos</title>
|
|
|
|
+
|
|
|
|
+ <para>Esta seção fornece exemplos que ilustram o cliente Java típico e as
|
|
|
|
+ interações do HPCC Systems<superscript>®</superscript>.</para>
|
|
|
|
+
|
|
|
|
+ <sect2>
|
|
|
|
+ <title>wsclient</title>
|
|
|
|
+
|
|
|
|
+ <para>Exemplo: o usuário deseja enviar e executar uma consulta ECL de um
|
|
|
|
+ cliente Java:</para>
|
|
|
|
+
|
|
|
|
+ <para>Use o pacote <emphasis role="bold">wsclient </emphasis>para conectar
|
|
|
|
+ ao HPCC Systems de destino.</para>
|
|
|
|
+
|
|
|
|
+ <para><programlisting> //Fetch platform object based on connection settings
|
|
|
|
+ //Provide the connection type, http|https, the ecl watch ip, and port,
|
|
|
|
+ //your ESP username and password (if required)
|
|
|
|
+
|
|
|
|
+ Platform platform = Platform.get("http", "ip", 8010, "username", "password");
|
|
|
|
+ HPCCWSClient connector = platform.getHPCCWSClient();
|
|
|
|
+</programlisting></para>
|
|
|
|
+
|
|
|
|
+ <para>Crie um objeto <emphasis>WorkunitInfo</emphasis> com código ECL e o
|
|
|
|
+ envie para o Web Service WECL.</para>
|
|
|
|
+
|
|
|
|
+ <para>O objeto <emphasis>WorkunitInfo</emphasis> contém todas as
|
|
|
|
+ informações necessárias para o HPCC compilar e executar uma consulta ECL
|
|
|
|
+ corretamente.</para>
|
|
|
|
+
|
|
|
|
+ <programlisting> WorkunitInfo wu=new WorkunitInfo();!
|
|
|
|
+ wu.setECL("output('Hello World');"); // The ECL to execute.
|
|
|
|
+ wu.setCluster("mythor"); // This can be hardcoded to a known cluster,
|
|
|
|
+ // or can be selected from
|
|
|
|
+ // valid cluster names clusterGroups[0] (above)</programlisting>
|
|
|
|
+
|
|
|
|
+ <para>Essa é apenas uma forma de enviar ECL, você também pode enviar ECL e
|
|
|
|
+ receber o WUID, que pode ser usado posteriormente para buscar resultados.
|
|
|
|
+ Os resultados (se bem-sucedidos) são retornados como uma Lista de Listas
|
|
|
|
+ de Objetos.</para>
|
|
|
|
+
|
|
|
|
+ <programlisting> List<List<Object>> results = connector.submitECLandGetResultsList(wu);
|
|
|
|
+
|
|
|
|
+ //logic to analyze results would need to be implemented.
|
|
|
|
+ int currentrs = 1;
|
|
|
|
+
|
|
|
|
+ for (List<Object> list : results)
|
|
|
|
+ {
|
|
|
|
+ Utils.print(System.out, "Resultset " + currentrs +":", false, true);
|
|
|
|
+ for (Object object : list)
|
|
|
|
+ {
|
|
|
|
+ System.out.print("[ " + object.toString() +" ]");
|
|
|
|
+ }
|
|
|
|
+ currentrs++;
|
|
|
|
+ System.out.println("");
|
|
|
|
+ }
|
|
|
|
+</programlisting>
|
|
|
|
+
|
|
|
|
+ <para>O exemplo anterior mostra como é simples codificar para essa
|
|
|
|
+ interface. Este modelo pode ser expandido para interagir com a maioria dos
|
|
|
|
+ ESP Web services e seus métodos.</para>
|
|
|
|
+
|
|
|
|
+ <para>Este conector pode ser usado para acionar vários métodos do
|
|
|
|
+ WebService HPCC. Por exemplo, o cliente pode solicitar uma lista de nomes
|
|
|
|
+ de cluster de destino disponíveis.</para>
|
|
|
|
+
|
|
|
|
+ <programlisting>List<String> clusters = connector.getAvailableTargetClusterNames(); </programlisting>
|
|
|
|
+
|
|
|
|
+ <para>ou grupos de clusters</para>
|
|
|
|
+
|
|
|
|
+ <programlisting>String[] clusterGroups = connector.getAvailableClusterGroups(); </programlisting>
|
|
|
|
+
|
|
|
|
+ <para>Que pode então ser usado como um dos parâmetros necessários para
|
|
|
|
+ outras ações WS, como espalhar um arquivo:</para>
|
|
|
|
+
|
|
|
|
+ <programlisting>connector.sprayFlatHPCCFile("persons", "mythor::persons", 155, clusters.get(0), true); </programlisting>
|
|
|
|
+ </sect2>
|
|
|
|
+
|
|
|
|
+ <sect2>
|
|
|
|
+ <title>DFSClient</title>
|
|
|
|
+
|
|
|
|
+ <para>Exemplo: O usuário deseja ler o arquivo "example::dataset" em
|
|
|
|
+ paralelo do HPCC Systems em um cliente Java.</para>
|
|
|
|
+
|
|
|
|
+ <sect3>
|
|
|
|
+ <title>Exemplo de Leitura:</title>
|
|
|
|
+
|
|
|
|
+ <para>O exemplo a seguir é para leitura em paralelo</para>
|
|
|
|
+
|
|
|
|
+ <programlisting>HPCCFile file = new HPCCFile("example::dataset", "http://127.0.0.1:8010" , "user", "pass");
|
|
|
|
+DataPartition[] fileParts = file.getFileParts();
|
|
|
|
+ArrayList<HPCCRecord> records = new ArrayList<HPCCRecord>();
|
|
|
|
+for (int i = 0; i < fileParts.length; i++)
|
|
|
|
+{
|
|
|
|
+ HpccRemoteFileReader<HPCCRecord> fileReader = null;
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ HPCCRecordBuilder recordBuilder = new
|
|
|
|
+ HPCCRecordBuilder(file.getProjectedRecordDefinition());
|
|
|
|
+ fileReader = new HpccRemoteFileReader<HPCCRecord>(fileParts[i],
|
|
|
|
+ file.getRecordDefinition(), recordBuilder);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e) { }
|
|
|
|
+ while (fileReader.hasNext())
|
|
|
|
+ {
|
|
|
|
+ HPCCRecord record = fileReader.next();
|
|
|
|
+ records.add(record);
|
|
|
|
+ }
|
|
|
|
+ fileReader.close();
|
|
|
|
+} </programlisting>
|
|
|
|
+ </sect3>
|
|
|
|
+
|
|
|
|
+ <sect3>
|
|
|
|
+ <title>Exemplo de Escrita:</title>
|
|
|
|
+
|
|
|
|
+ <para>Exaemplo: Usuário deseja fazer o spray do datasetser dentro de
|
|
|
|
+ arquivo lógido do HPCC Systems chamado "example::dataset.</para>
|
|
|
|
+
|
|
|
|
+ <programlisting>FieldDef[] fieldDefs = new FieldDef[2];
|
|
|
|
+fieldDefs[0] = new FieldDef("key", FieldType.INTEGER, "lNTEGER4", 4, true, false,
|
|
|
|
+ HpccSrcType.LITTLE_ENDIAN, new FieldDef[0]);
|
|
|
|
+fieldDefs[1] = new FieldDef("value", FieldType.STRING, "STRING", 0, false, false,
|
|
|
|
+ HpccSrcType.UTF8, new FieldDef[0]);
|
|
|
|
+FieldDef recordDef = new FieldDef("RootRecord", FieldType.RECORD, "rec", 4, false, false,
|
|
|
|
+ HpccSrcType.LITTLE_ENDIAN, fieldDefs);
|
|
|
|
+
|
|
|
|
+String eclRecordDefn = RecordDefinitionTranslator.toECLRecord(recordDef);
|
|
|
|
+
|
|
|
|
+// See WSClient documentation on connection / construction of WSClient
|
|
|
|
+Platform platform;
|
|
|
|
+HPCCWsClient wsclient;
|
|
|
|
+
|
|
|
|
+HPCCWsDFUClient dfuClient = wsclient.getWsDFUClient();
|
|
|
|
+DFUCreateFileWrapper createResult = dfuClient.createFile("example::dataset", "mythor",
|
|
|
|
+ eclRecordDefn, 300, false, DFUFileTypeWrapper.Flat, "");
|
|
|
|
+DFUFilePartWrapper[] dfuFileParts = createResult.getFileParts();
|
|
|
|
+DataPartition[] hpccPartitions = DataPartition.createPartitions(dfuFileParts,
|
|
|
|
+ new NullRemapper(new RemapInfo(), createResult.getFileAccessInfo()),
|
|
|
|
+dfuFileParts.length, createResult.getFileAccessInfoBlob());
|
|
|
|
+
|
|
|
|
+//------------------------------------------------------------------------------
|
|
|
|
+// Write partitions to file parts
|
|
|
|
+//------------------------------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ArrayList<HPCCRecord> records = new ArrayList<HPCCRecord>();
|
|
|
|
+
|
|
|
|
+int recordsPerPartition = records.size() / dfuFileParts.length;
|
|
|
|
+int residualRecords = records.size() % dfuFileParts.length;
|
|
|
|
+
|
|
|
|
+int recordCount = 0;
|
|
|
|
+int bytesWritten = 0;
|
|
|
|
+for (int partitionIndex = 0; partitionIndex < hpccPartitions.length; partitionIndex++)
|
|
|
|
+{
|
|
|
|
+ int numRecordsInPartition = recordsPerPartition;
|
|
|
|
+ if (partitionIndex == dfuFileParts.length - 1)
|
|
|
|
+ {
|
|
|
|
+ numRecordsInPartition += residualRecords;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ HPCCRecordAccessor recordAccessor = new HPCCRecordAccessor(recordDef);
|
|
|
|
+ HPCCRemoteFileWriter<HPCCRecord> fileWriter = new
|
|
|
|
+ HPCCRemoteFileWriter<HPCCRecord>(hpccPartitions[partitionIndex], recordDef,
|
|
|
|
+ recordAccessor, CompressionAlgorithm.NONE);
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ for (int j = 0; j < numRecordsInPartition; j++, recordCount++)
|
|
|
|
+ {
|
|
|
|
+ fileWriter.writeRecord(records.get(recordCount));
|
|
|
|
+ }
|
|
|
|
+ fileWriter.close();
|
|
|
|
+ bytesWritten += fileWriter.getBytesWritten();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//------------------------------------------------------------------------------
|
|
|
|
+// Publish and finalize the file
|
|
|
|
+//------------------------------------------------------------------------------
|
|
|
|
+
|
|
|
|
+dfuClient.publishFile(createResult.getFileID(), eclRecordDefn, recordCount, bytesWritten, true);</programlisting>
|
|
|
|
+ </sect3>
|
|
|
|
+ </sect2>
|
|
|
|
+</sect1>
|