Search in sources :

Example 21 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class ExtensionPointIntegrationTest method testExtensionPointMapConcurrency.

@Test
public void testExtensionPointMapConcurrency() throws InterruptedException {
    final ILogChannel log = mock(ILogChannel.class);
    List<Runnable> parallelTasksList = new ArrayList<>(TOTAL_THREADS_TO_RUN);
    for (int i = 0; i < TOTAL_THREADS_TO_RUN; i++) {
        parallelTasksList.add(() -> {
            HopExtensionPoint hopExtensionPoint = getRandomHopExtensionPoint();
            IPlugin pluginInterface = PluginRegistry.getInstance().getPlugin(ExtensionPointPluginType.class, "id" + hopExtensionPoint.id);
            try {
                PluginRegistry.getInstance().removePlugin(ExtensionPointPluginType.class, pluginInterface);
                PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
            } catch (HopPluginException e) {
                e.printStackTrace();
            } catch (NullPointerException e) {
            // NullPointerException can be thrown if trying to remove a plugin that doesn't exit,
            // discarding occurence
            }
            ExtensionPointMap.getInstance().reInitialize();
            try {
                ExtensionPointMap.getInstance().callExtensionPoint(log, null, hopExtensionPoint.id, null);
            } catch (HopException e) {
                e.printStackTrace();
            }
        });
    }
    assertConcurrent(parallelTasksList);
}
Also used : ILogChannel(org.apache.hop.core.logging.ILogChannel) HopException(org.apache.hop.core.exception.HopException) ArrayList(java.util.ArrayList) HopPluginException(org.apache.hop.core.exception.HopPluginException) IPlugin(org.apache.hop.core.plugins.IPlugin) Test(org.junit.Test)

Example 22 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class DrawDiffOnActionExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, Object object) throws HopException {
    if (!(object instanceof WorkflowPainter)) {
        return;
    }
    WorkflowPainter painter = (WorkflowPainter) object;
    Point offset = painter.getOffset();
    IGc gc = painter.getGc();
    WorkflowMeta workflowMeta = painter.getWorkflowMeta();
    try {
        workflowMeta.getActions().stream().filter(je -> je.getAttribute(ATTR_GIT, ATTR_STATUS) != null).forEach(je -> {
            if (workflowMeta.getWorkflowVersion() == null ? false : workflowMeta.getWorkflowVersion().startsWith("git")) {
                String status = je.getAttribute(ATTR_GIT, ATTR_STATUS);
                Point n = je.getLocation();
                String location;
                if (status.equals(REMOVED)) {
                    location = "removed.svg";
                } else if (status.equals(CHANGED)) {
                    location = "changed.svg";
                } else if (status.equals(ADDED)) {
                    location = "added.svg";
                } else {
                    // Unchanged
                    return;
                }
                int iconSize = ConstUi.ICON_SIZE;
                try {
                    iconSize = PropsUi.getInstance().getIconSize();
                } catch (Exception e) {
                // Exception when accessed from Hop Server
                }
                int x = (n.x + iconSize + offset.x) - (iconSize / 4);
                int y = n.y + offset.y - (iconSize / 4);
                try {
                    gc.drawImage(new SvgFile(location, getClass().getClassLoader()), x, y, iconSize / 4, iconSize / 4, gc.getMagnification(), 0);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
                je.getAttributesMap().remove(ATTR_GIT);
            }
        });
    } catch (Exception e) {
        throw new HopException("Error drawing status icon on action", e);
    }
}
Also used : ILogChannel(org.apache.hop.core.logging.ILogChannel) SvgFile(org.apache.hop.core.svg.SvgFile) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IVariables(org.apache.hop.core.variables.IVariables) WorkflowPainter(org.apache.hop.workflow.WorkflowPainter) HopDiff(org.apache.hop.git.HopDiff) HopException(org.apache.hop.core.exception.HopException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) PropsUi(org.apache.hop.ui.core.PropsUi) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) IGc(org.apache.hop.core.gui.IGc) Point(org.apache.hop.core.gui.Point) ConstUi(org.apache.hop.ui.core.ConstUi) IGc(org.apache.hop.core.gui.IGc) HopException(org.apache.hop.core.exception.HopException) WorkflowPainter(org.apache.hop.workflow.WorkflowPainter) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) SvgFile(org.apache.hop.core.svg.SvgFile) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) HopException(org.apache.hop.core.exception.HopException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta)

Example 23 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class DrawDiffOnTransformExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, Object object) throws HopException {
    if (!(object instanceof PipelinePainter)) {
        return;
    }
    PipelinePainter painter = (PipelinePainter) object;
    Point offset = painter.getOffset();
    IGc gc = painter.getGc();
    PipelineMeta pipelineMeta = painter.getPipelineMeta();
    try {
        pipelineMeta.getTransforms().stream().filter(transform -> transform.getAttribute(ATTR_GIT, ATTR_STATUS) != null).forEach(transform -> {
            if (pipelineMeta.getPipelineVersion() != null && pipelineMeta.getPipelineVersion().startsWith("git")) {
                String status = transform.getAttribute(ATTR_GIT, ATTR_STATUS);
                Point n = transform.getLocation();
                String location;
                if (status.equals(REMOVED)) {
                    location = "removed.svg";
                } else if (status.equals(CHANGED)) {
                    location = "changed.svg";
                } else if (status.equals(ADDED)) {
                    location = "added.svg";
                } else {
                    // Unchanged
                    return;
                }
                int iconSize = ConstUi.ICON_SIZE;
                try {
                    iconSize = PropsUi.getInstance().getIconSize();
                } catch (Exception e) {
                // Exception when accessed from Hop Server
                }
                int x = (n.x + iconSize + offset.x) - (iconSize / 4);
                int y = n.y + offset.y - (iconSize / 4);
                try {
                    gc.drawImage(new SvgFile(location, getClass().getClassLoader()), x, y, iconSize / 2, iconSize / 2, gc.getMagnification(), 0);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
                transform.getAttributesMap().remove(ATTR_GIT);
            }
        });
    } catch (Exception e) {
        throw new HopException("Error drawing status on transform", e);
    }
}
Also used : ILogChannel(org.apache.hop.core.logging.ILogChannel) SvgFile(org.apache.hop.core.svg.SvgFile) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IVariables(org.apache.hop.core.variables.IVariables) HopDiff(org.apache.hop.git.HopDiff) HopException(org.apache.hop.core.exception.HopException) PipelinePainter(org.apache.hop.pipeline.PipelinePainter) PropsUi(org.apache.hop.ui.core.PropsUi) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) IGc(org.apache.hop.core.gui.IGc) Point(org.apache.hop.core.gui.Point) ConstUi(org.apache.hop.ui.core.ConstUi) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) IGc(org.apache.hop.core.gui.IGc) HopException(org.apache.hop.core.exception.HopException) PipelinePainter(org.apache.hop.pipeline.PipelinePainter) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) SvgFile(org.apache.hop.core.svg.SvgFile) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) HopException(org.apache.hop.core.exception.HopException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Example 24 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class MongoDbOutputMetaInjectionTest method setHopLogFactoryWithMock.

public static void setHopLogFactoryWithMock() {
    ILogChannelFactory logChannelInterfaceFactory = mock(ILogChannelFactory.class);
    ILogChannel logChannelInterface = mock(ILogChannel.class);
    when(logChannelInterfaceFactory.create(any())).thenReturn(logChannelInterface);
    HopLogStore.setLogChannelFactory(logChannelInterfaceFactory);
}
Also used : ILogChannel(org.apache.hop.core.logging.ILogChannel) ILogChannelFactory(org.apache.hop.core.logging.ILogChannelFactory)

Example 25 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class MongoDbOutputDataTest method testApplyIndexesOptions.

@Test
public void testApplyIndexesOptions() throws HopException, MongoDbException {
    MongoDbOutputData data = new MongoDbOutputData();
    ILogChannel log = LogChannel.GENERAL;
    DBCollection collection = mock(DBCollection.class);
    MongoCollectionWrapper collectionWrapper = spy(new DefaultMongoCollectionWrapper(collection));
    data.setCollection(collectionWrapper);
    ArgumentCaptor<BasicDBObject> captorIndexes = ArgumentCaptor.forClass(BasicDBObject.class);
    ArgumentCaptor<BasicDBObject> captorOptions = ArgumentCaptor.forClass(BasicDBObject.class);
    doNothing().when(collectionWrapper).createIndex(captorIndexes.capture(), captorOptions.capture());
    MongoIndex index = new MongoIndex();
    index.pathToFields = "FirstName:1";
    index.drop = false;
    index.sparse = false;
    index.unique = false;
    // Test with all options false
    data.applyIndexes(Collections.singletonList(index), log, false);
    BasicDBObject createdIndex = captorIndexes.getValue();
    BasicDBObject createdOptions = captorOptions.getValue();
    assertEquals(1, createdIndex.size());
    assertTrue(createdIndex.containsField("FirstName"));
    assertEquals("1", createdIndex.getString("FirstName"));
    assertTrue(createdOptions.containsField("background"));
    assertTrue(createdOptions.getBoolean("background"));
    assertTrue(createdOptions.containsField("sparse"));
    assertFalse(createdOptions.getBoolean("sparse"));
    assertTrue(createdOptions.containsField("unique"));
    assertFalse(createdOptions.getBoolean("unique"));
    // Test with only "sparse" true
    index.sparse = true;
    index.unique = false;
    data.applyIndexes(Collections.singletonList(index), log, false);
    createdIndex = captorIndexes.getValue();
    createdOptions = captorOptions.getValue();
    assertEquals(1, createdIndex.size());
    assertTrue(createdIndex.containsField("FirstName"));
    assertEquals("1", createdIndex.getString("FirstName"));
    assertTrue(createdOptions.containsField("background"));
    assertTrue(createdOptions.getBoolean("background"));
    assertTrue(createdOptions.containsField("sparse"));
    assertTrue(createdOptions.getBoolean("sparse"));
    assertTrue(createdOptions.containsField("unique"));
    assertFalse(createdOptions.getBoolean("unique"));
    // Test with only "unique" true
    index.sparse = false;
    index.unique = true;
    data.applyIndexes(Collections.singletonList(index), log, false);
    createdIndex = captorIndexes.getValue();
    createdOptions = captorOptions.getValue();
    assertEquals(1, createdIndex.size());
    assertTrue(createdIndex.containsField("FirstName"));
    assertEquals("1", createdIndex.getString("FirstName"));
    assertTrue(createdOptions.containsField("background"));
    assertTrue(createdOptions.getBoolean("background"));
    assertTrue(createdOptions.containsField("sparse"));
    assertFalse(createdOptions.getBoolean("sparse"));
    assertTrue(createdOptions.containsField("unique"));
    assertTrue(createdOptions.getBoolean("unique"));
    // Test with "sparse" and "unique" true
    index.sparse = true;
    index.unique = true;
    data.applyIndexes(Collections.singletonList(index), log, false);
    createdIndex = captorIndexes.getValue();
    createdOptions = captorOptions.getValue();
    assertEquals(1, createdIndex.size());
    assertTrue(createdIndex.containsField("FirstName"));
    assertEquals("1", createdIndex.getString("FirstName"));
    assertTrue(createdOptions.containsField("background"));
    assertTrue(createdOptions.getBoolean("background"));
    assertTrue(createdOptions.containsField("sparse"));
    assertTrue(createdOptions.getBoolean("sparse"));
    assertTrue(createdOptions.containsField("unique"));
    assertTrue(createdOptions.getBoolean("unique"));
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) ILogChannel(org.apache.hop.core.logging.ILogChannel) MongoIndex(org.apache.hop.pipeline.transforms.mongodboutput.MongoDbOutputMeta.MongoIndex) DefaultMongoCollectionWrapper(org.apache.hop.mongo.wrapper.collection.DefaultMongoCollectionWrapper) MongoCollectionWrapper(org.apache.hop.mongo.wrapper.collection.MongoCollectionWrapper) DefaultMongoCollectionWrapper(org.apache.hop.mongo.wrapper.collection.DefaultMongoCollectionWrapper) Test(org.junit.Test)

Aggregations

ILogChannel (org.apache.hop.core.logging.ILogChannel)47 HopException (org.apache.hop.core.exception.HopException)20 Test (org.junit.Test)19 Point (org.apache.hop.core.gui.Point)15 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 PrintWriter (java.io.PrintWriter)12 StringWriter (java.io.StringWriter)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)10 IVariables (org.apache.hop.core.variables.IVariables)9 Pipeline (org.apache.hop.pipeline.Pipeline)9 ExtensionPoint (org.apache.hop.core.extension.ExtensionPoint)8 IExtensionPoint (org.apache.hop.core.extension.IExtensionPoint)7 SimpleDateFormat (java.text.SimpleDateFormat)6 Result (org.apache.hop.core.Result)6 NeoConnection (org.apache.hop.neo4j.shared.NeoConnection)6 Transaction (org.neo4j.driver.Transaction)6 Date (java.util.Date)4