Search in sources :

Example 96 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.

the class TestCoordUpdateXCommand method testDefinitionChange.

// test definition change
public void testDefinitionChange() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile1 = new File(getTestCaseDir(), "coordinator.xml");
    String jobId = setupCoord(conf, "coord-multiple-input-instance3.xml");
    CoordinatorJobBean job = getCoordJobs(jobId);
    Element processedJobXml = XmlUtils.parseXml(job.getJobXml());
    Namespace namespace = processedJobXml.getNamespace();
    String text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:latest(0)}");
    Reader reader = IOUtils.getResourceAsReader("coord-multiple-input-instance4.xml", -1);
    Writer writer = new OutputStreamWriter(new FileOutputStream(appPathFile1), StandardCharsets.UTF_8);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile1.toURI().toString());
    job = getCoordJobs(jobId);
    CoordUpdateXCommand update = new CoordUpdateXCommand(false, conf, jobId);
    update.call();
    job = getCoordJobs(jobId);
    processedJobXml = XmlUtils.parseXml(job.getJobXml());
    namespace = processedJobXml.getNamespace();
    text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:future(0, 1)}");
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom2.Element) FileOutputStream(java.io.FileOutputStream) Reader(java.io.Reader) StringReader(java.io.StringReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Namespace(org.jdom2.Namespace) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 97 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.

the class TestHiveActionExecutor method testHiveAction.

public void testHiveAction() throws Exception {
    Path inputDir = new Path(getFsTestCaseDir(), INPUT_DIRNAME);
    Path outputDir = new Path(getFsTestCaseDir(), OUTPUT_DIRNAME);
    String hiveScript = getHiveScript(inputDir.toString(), outputDir.toString());
    FileSystem fs = getFileSystem();
    {
        Path script = new Path(getAppPath(), HIVE_SCRIPT_FILENAME);
        Writer scriptWriter = new OutputStreamWriter(fs.create(script), StandardCharsets.UTF_8);
        scriptWriter.write(hiveScript);
        scriptWriter.close();
        Writer dataWriter = new OutputStreamWriter(fs.create(new Path(inputDir, DATA_FILENAME)), StandardCharsets.UTF_8);
        dataWriter.write(SAMPLE_DATA_TEXT);
        dataWriter.close();
        Context context = createContext(getActionScriptXml());
        Namespace ns = Namespace.getNamespace("uri:oozie:hive-action:0.2");
        final String launcherId = submitAction(context, ns);
        waitUntilYarnAppDoneAndAssertSuccess(launcherId, 180 * 1000);
        Configuration conf = new XConfiguration();
        conf.set("user.name", getTestUser());
        Map<String, String> actionData = LauncherHelper.getActionData(getFileSystem(), context.getActionDir(), conf);
        assertFalse(LauncherHelper.hasIdSwap(actionData));
        HiveActionExecutor ae = new HiveActionExecutor();
        ae.check(context, context.getAction());
        assertTrue(launcherId.equals(context.getAction().getExternalId()));
        assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
        ae.end(context, context.getAction());
        assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
        assertNotNull(context.getExternalChildIDs());
        // while this works in a real cluster, it does not with miniMR
        // assertTrue(outputData.getProperty(LauncherMain.HADOOP_JOBS).trim().length() > 0);
        // assertTrue(!actionData.get(LauncherAMUtils.ACTION_DATA_EXTERNAL_CHILD_IDS).isEmpty());
        assertTrue(fs.exists(outputDir));
        assertTrue(fs.isDirectory(outputDir));
    }
    {
        Context context = createContext(getActionQueryXml(hiveScript));
        Namespace ns = Namespace.getNamespace("uri:oozie:hive-action:0.6");
        final String launcherId = submitAction(context, ns);
        waitUntilYarnAppDoneAndAssertSuccess(launcherId, 180 * 1000);
        Configuration conf = new XConfiguration();
        conf.set("user.name", getTestUser());
        Map<String, String> actionData = LauncherHelper.getActionData(getFileSystem(), context.getActionDir(), conf);
        assertFalse(LauncherHelper.hasIdSwap(actionData));
        HiveActionExecutor ae = new HiveActionExecutor();
        ae.check(context, context.getAction());
        assertTrue(launcherId.equals(context.getAction().getExternalId()));
        assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
        ae.end(context, context.getAction());
        assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
        assertNotNull(context.getAction().getExternalChildIDs());
        // while this works in a real cluster, it does not with miniMR
        // assertTrue(outputData.getProperty(LauncherMain.HADOOP_JOBS).trim().length() > 0);
        // assertTrue(!actionData.get(LauncherAMUtils.ACTION_DATA_EXTERNAL_CHILD_IDS).isEmpty());
        assertTrue(fs.exists(outputDir));
        assertTrue(fs.isDirectory(outputDir));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) Map(java.util.Map) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Namespace(org.jdom2.Namespace)

Example 98 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project goobi-viewer-indexer by intranda.

the class JDomXP method splitLidoFile.

/**
 * Splits a multi-record LIDO document into a list of individual record documents.
 *
 * @throws io.goobi.viewer.indexer.exceptions.FatalIndexerException
 * @should split multi record documents correctly
 * @should leave single record documents as is
 * @should return empty list for non lido documents
 * @should return empty list for non-existing files
 * @should return empty list given null
 * @param file a {@link java.io.File} object.
 * @return a {@link java.util.List} object.
 */
public static List<Document> splitLidoFile(File file) throws FatalIndexerException {
    if (file == null) {
        return Collections.emptyList();
    }
    try {
        JDomXP xp = new JDomXP(file);
        if (xp.doc.getRootElement().getName().equals("lidoWrap")) {
            // Multiple LIDO document file
            Namespace nsXsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            List<Element> lidoElements = xp.doc.getRootElement().getChildren("lido", Configuration.getInstance().getNamespaces().get("lido"));
            if (lidoElements != null) {
                List<Document> ret = new ArrayList<>(lidoElements.size());
                for (Element eleLidoDoc : lidoElements) {
                    Document doc = new Document();
                    doc.setRootElement(eleLidoDoc.clone());
                    doc.getRootElement().addNamespaceDeclaration(nsXsi);
                    doc.getRootElement().setAttribute(new Attribute("schemaLocation", "http://www.lido-schema.org http://www.lido-schema.org/schema/v1.0/lido-v1.0.xsd", nsXsi));
                    ret.add(doc);
                }
                return ret;
            }
        } else if (xp.doc.getRootElement().getName().equals("lido")) {
            // Single LIDO document file
            return Collections.singletonList(xp.doc);
        } else {
            logger.warn("Unknown root element: {}", xp.doc.getRootElement().getName());
        }
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (JDOMException e) {
        logger.error(e.getMessage());
    }
    return Collections.emptyList();
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) Namespace(org.jdom2.Namespace)

Example 99 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project maven-archetype by apache.

the class XMLOutputter method printAttributes.

/**
 * This will handle printing of a <code>{@link Attribute}</code> list.
 *
 * @param attributes <code>List</code> of Attribute objcts
 * @param out        <code>Writer</code> to use
 */
protected void printAttributes(Writer out, List<?> attributes, Element parent, NamespaceStack namespaces) throws IOException {
    // Set prefixes = new HashSet();
    for (int i = 0; i < attributes.size(); i++) {
        Attribute attribute = (Attribute) attributes.get(i);
        Namespace ns = attribute.getNamespace();
        if ((ns != Namespace.NO_NAMESPACE) && (ns != Namespace.XML_NAMESPACE)) {
            printNamespace(out, ns, namespaces);
        }
        out.write(" ");
        printQualifiedName(out, attribute);
        out.write("=");
        out.write("\"");
        out.write(escapeAttributeEntities(attribute.getValue()));
        out.write("\"");
    }
}
Also used : Attribute(org.jdom2.Attribute) Namespace(org.jdom2.Namespace)

Example 100 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project qpp-conversion-tool by CMSgov.

the class PiMeasurePerformedRnRDecoderTest method internalDecodeReturnsTreeContinue.

@Test
void internalDecodeReturnsTreeContinue() {
    // set-up
    PiMeasurePerformedRnRDecoder objectUnderTest = new PiMeasurePerformedRnRDecoder(new Context());
    Namespace rootns = Namespace.getNamespace("urn:hl7-org:v3");
    Namespace ns = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    Element element = new Element("organizer", rootns);
    Element templateIdElement = new Element("templateId", rootns).setAttribute("root", "2.16.840.1.113883.10.20.27.3.28");
    Element referenceElement = new Element("reference", rootns);
    Element externalDocumentElement = new Element("externalDocument", rootns);
    Element idElement = new Element("id", rootns).setAttribute("extension", MEASURE_ID);
    externalDocumentElement.addContent(idElement);
    referenceElement.addContent(externalDocumentElement);
    element.addContent(templateIdElement);
    element.addContent(referenceElement);
    element.addNamespaceDeclaration(ns);
    Node piMeasurePerformedNode = new Node();
    objectUnderTest.setNamespace(element.getNamespace());
    // execute
    DecodeResult decodeResult = objectUnderTest.decode(element, piMeasurePerformedNode);
    // assert
    assertThat(decodeResult).isEqualTo(DecodeResult.TREE_CONTINUE);
    String actualMeasureId = piMeasurePerformedNode.getValue("measureId");
    assertThat(actualMeasureId).isEqualTo(MEASURE_ID);
}
Also used : Context(gov.cms.qpp.conversion.Context) Element(org.jdom2.Element) Node(gov.cms.qpp.conversion.model.Node) Namespace(org.jdom2.Namespace) Test(org.junit.jupiter.api.Test)

Aggregations

Namespace (org.jdom2.Namespace)105 Element (org.jdom2.Element)87 IOException (java.io.IOException)24 XConfiguration (org.apache.oozie.util.XConfiguration)19 ArrayList (java.util.ArrayList)16 Configuration (org.apache.hadoop.conf.Configuration)15 HashMap (java.util.HashMap)14 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)14 StringReader (java.io.StringReader)13 List (java.util.List)13 Path (org.apache.hadoop.fs.Path)12 JDOMException (org.jdom2.JDOMException)10 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)9 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)9 Attribute (org.jdom2.Attribute)9 Writer (java.io.Writer)8 RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)7 Map (java.util.Map)7 Document (org.jdom2.Document)7 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6