use of org.apache.hop.core.row.RowBuffer in project hop by apache.
the class Pipeline method retrieveComponentOutput.
@Override
public void retrieveComponentOutput(IVariables variables, String componentName, int copyNr, int nrRows, IPipelineComponentRowsReceived rowsReceived) throws HopException {
ITransform iTransform = getTransform(componentName, copyNr);
if (iTransform == null) {
throw new HopException("Unable to find transform '" + componentName + "', copy " + copyNr + " to retrieve output rows from");
}
RowBuffer rowBuffer = new RowBuffer(pipelineMeta.getTransformFields(variables, componentName));
iTransform.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(IRowMeta rowMeta, Object[] row) throws HopTransformException {
if (rowBuffer.getBuffer().size() < nrRows) {
rowBuffer.getBuffer().add(row);
if (rowBuffer.getBuffer().size() >= nrRows) {
try {
rowsReceived.rowsReceived(Pipeline.this, rowBuffer);
} catch (HopException e) {
throw new HopTransformException("Error recieving rows from '" + componentName + " copy " + copyNr, e);
}
}
}
}
});
}
use of org.apache.hop.core.row.RowBuffer in project hop by apache.
the class PluginRegistry method getPluginInformation.
/**
* @param pluginType the type of plugin to get information for
* @return a row buffer containing plugin information for the given plugin type
* @throws HopPluginException
*/
public RowBuffer getPluginInformation(Class<? extends IPluginType> pluginType) throws HopPluginException {
RowBuffer rowBuffer = new RowBuffer(getPluginInformationRowMeta());
for (IPlugin plugin : getPlugins(pluginType)) {
Object[] row = new Object[getPluginInformationRowMeta().size()];
int rowIndex = 0;
row[rowIndex++] = getPluginType(plugin.getPluginType()).getName();
row[rowIndex++] = plugin.getIds()[0];
row[rowIndex++] = plugin.getName();
row[rowIndex++] = Const.NVL(plugin.getDescription(), "");
row[rowIndex++] = Const.NVL(plugin.getImageFile(), "");
row[rowIndex++] = Const.NVL(plugin.getCategory(), "");
row[rowIndex++] = String.join(",", plugin.getKeywords());
row[rowIndex++] = Const.NVL(plugin.getDocumentationUrl(), "");
row[rowIndex++] = plugin.getClassMap().values().toString();
row[rowIndex++] = String.join(",", plugin.getLibraries());
rowBuffer.getBuffer().add(row);
}
return rowBuffer;
}
use of org.apache.hop.core.row.RowBuffer in project hop by apache.
the class HopGuiPipelineGraph method setToolTip.
private AreaOwner setToolTip(int x, int y, int screenX, int screenY) {
AreaOwner subject = null;
if (!hopGui.getProps().showToolTips()) {
return subject;
}
canvas.setToolTipText(null);
String newTip = null;
Image tipImage = null;
final PipelineHopMeta hi = findPipelineHop(x, y);
// check the area owner list...
//
StringBuilder tip = new StringBuilder();
AreaOwner areaOwner = getVisibleAreaOwner(x, y);
if (areaOwner != null && areaOwner.getAreaType() != null) {
AreaType areaType = areaOwner.getAreaType();
switch(areaType) {
case TRANSFORM_PARTITIONING:
TransformMeta transform = (TransformMeta) areaOwner.getParent();
tip.append("Transform partitioning:").append(Const.CR).append("-----------------------").append(Const.CR);
tip.append(transform.getTransformPartitioningMeta().toString()).append(Const.CR);
if (transform.getTargetTransformPartitioningMeta() != null) {
tip.append(Const.CR).append(Const.CR).append("TARGET: " + transform.getTargetTransformPartitioningMeta().toString()).append(Const.CR);
}
break;
case TRANSFORM_FAILURE_ICON:
String log = (String) areaOwner.getParent();
tip.append(log);
tipImage = GuiResource.getInstance().getImageFailure();
break;
case HOP_COPY_ICON:
transform = (TransformMeta) areaOwner.getParent();
tip.append(BaseMessages.getString(PKG, "PipelineGraph.Hop.Tooltip.HopTypeCopy", transform.getName(), Const.CR));
tipImage = GuiResource.getInstance().getImageCopyHop();
break;
case ROW_DISTRIBUTION_ICON:
transform = (TransformMeta) areaOwner.getParent();
tip.append(BaseMessages.getString(PKG, "PipelineGraph.Hop.Tooltip.RowDistribution", transform.getName(), transform.getRowDistribution() == null ? "" : transform.getRowDistribution().getDescription()));
tip.append(Const.CR);
tipImage = GuiResource.getInstance().getImageBalance();
break;
case HOP_INFO_ICON:
TransformMeta from = (TransformMeta) areaOwner.getParent();
TransformMeta to = (TransformMeta) areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "PipelineGraph.Hop.Tooltip.HopTypeInfo", to.getName(), from.getName(), Const.CR));
tipImage = GuiResource.getInstance().getImageInfo();
break;
case HOP_ERROR_ICON:
from = (TransformMeta) areaOwner.getParent();
to = (TransformMeta) areaOwner.getOwner();
areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "PipelineGraph.Hop.Tooltip.HopTypeError", from.getName(), to.getName(), Const.CR));
tipImage = GuiResource.getInstance().getImageError();
break;
case HOP_INFO_TRANSFORM_COPIES_ERROR:
from = (TransformMeta) areaOwner.getParent();
to = (TransformMeta) areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "PipelineGraph.Hop.Tooltip.InfoTransformCopies", from.getName(), to.getName(), Const.CR));
tipImage = GuiResource.getInstance().getImageError();
break;
case HOP_INFO_TRANSFORMS_PARTITIONED:
from = (TransformMeta) areaOwner.getParent();
to = (TransformMeta) areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "PipelineGraph.Hop.Tooltip.InfoTransformsPartitioned", from.getName(), to.getName(), Const.CR));
tipImage = GuiResource.getInstance().getImageError();
break;
case TRANSFORM_INPUT_HOP_ICON:
tip.append(BaseMessages.getString(PKG, "PipelineGraph.TransformInputConnector.Tooltip"));
tipImage = GuiResource.getInstance().getImageInput();
break;
case TRANSFORM_OUTPUT_HOP_ICON:
tip.append(BaseMessages.getString(PKG, "PipelineGraph.TransformOutputConnector.Tooltip"));
tipImage = GuiResource.getInstance().getImageOutput();
break;
case TRANSFORM_INFO_HOP_ICON:
ITransformIOMeta ioMeta = (ITransformIOMeta) areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "PipelineGraph.TransformMetaConnector.Tooltip") + Const.CR + ioMeta.toString());
tipImage = GuiResource.getInstance().getImageInfo();
break;
case TRANSFORM_TARGET_HOP_ICON:
IStream stream = (IStream) areaOwner.getOwner();
tip.append(stream.getDescription());
if (stream.getStreamIcon() == StreamIcon.TRUE) {
tipImage = GuiResource.getInstance().getImageTrue();
} else if (stream.getStreamIcon() == StreamIcon.FALSE) {
tipImage = GuiResource.getInstance().getImageFalse();
} else {
tipImage = GuiResource.getInstance().getImageTarget();
}
break;
case TRANSFORM_ERROR_HOP_ICON:
TransformMeta transformMeta = (TransformMeta) areaOwner.getParent();
if (transformMeta.supportsErrorHandling()) {
tip.append(BaseMessages.getString(PKG, "PipelineGraph.TransformSupportsErrorHandling.Tooltip"));
} else {
tip.append(BaseMessages.getString(PKG, "PipelineGraph.TransformDoesNotSupportsErrorHandling.Tooltip"));
}
tipImage = GuiResource.getInstance().getImageError();
break;
case TRANSFORM_EDIT_ICON:
tip.append(BaseMessages.getString(PKG, "PipelineGraph.EditTransform.Tooltip"));
tipImage = GuiResource.getInstance().getImageEdit();
break;
case TRANSFORM_INJECT_ICON:
Object injection = areaOwner.getOwner();
if (injection != null) {
tip.append(BaseMessages.getString(PKG, "PipelineGraph.TransformInjectionSupported.Tooltip"));
} else {
tip.append(BaseMessages.getString(PKG, "PipelineGraph.TransformInjectionNotSupported.Tooltip"));
}
tipImage = GuiResource.getInstance().getImageInject();
break;
case TRANSFORM_MENU_ICON:
tip.append(BaseMessages.getString(PKG, "PipelineGraph.ShowMenu.Tooltip"));
tipImage = GuiResource.getInstance().getImageContextMenu();
break;
case TRANSFORM_ICON:
TransformMeta iconTransformMeta = (TransformMeta) areaOwner.getOwner();
if (iconTransformMeta.isDeprecated()) {
// only need tooltip if transform is deprecated
tip.append(BaseMessages.getString(PKG, "PipelineGraph.DeprecatedTransform.Tooltip.Title")).append(Const.CR);
String tipNext = BaseMessages.getString(PKG, "PipelineGraph.DeprecatedTransform.Tooltip.Message1", iconTransformMeta.getName());
int length = tipNext.length() + 5;
for (int i = 0; i < length; i++) {
tip.append("-");
}
tip.append(Const.CR).append(tipNext).append(Const.CR);
tip.append(BaseMessages.getString(PKG, "PipelineGraph.DeprecatedTransform.Tooltip.Message2"));
if (!Utils.isEmpty(iconTransformMeta.getSuggestion()) && !(iconTransformMeta.getSuggestion().startsWith("!") && iconTransformMeta.getSuggestion().endsWith("!"))) {
tip.append(" ");
tip.append(BaseMessages.getString(PKG, "PipelineGraph.DeprecatedTransform.Tooltip.Message3", iconTransformMeta.getSuggestion()));
}
tipImage = GuiResource.getInstance().getImageDeprecated();
}
break;
case TRANSFORM_OUTPUT_DATA:
RowBuffer rowBuffer = (RowBuffer) areaOwner.getOwner();
if (rowBuffer != null && !rowBuffer.isEmpty()) {
tip.append("Available output rows: " + rowBuffer.size());
tipImage = GuiResource.getInstance().getImageData();
}
break;
default:
//
try {
HopGuiTooltipExtension tooltipExt = new HopGuiTooltipExtension(x, y, screenX, screenY, areaOwner, tip);
ExtensionPointHandler.callExtensionPoint(hopGui.getLog(), variables, HopExtensionPoint.HopGuiPipelineGraphAreaHover.name(), tooltipExt);
tipImage = tooltipExt.tooltipImage;
} catch (Exception ex) {
hopGui.getLog().logError("Error calling extension point " + HopExtensionPoint.HopGuiPipelineGraphAreaHover.name(), ex);
}
break;
}
}
if (hi != null && tip.length() == 0) {
// We clicked on a HOP!
// Set the tooltip for the hop:
tip.append(Const.CR).append(BaseMessages.getString(PKG, "PipelineGraph.Dialog.HopInfo")).append(newTip = hi.toString()).append(Const.CR);
}
if (tip.length() == 0) {
newTip = null;
} else {
newTip = tip.toString();
}
if (newTip == null) {
toolTip.setVisible(false);
if (hi != null) {
// We clicked on a HOP!
// Set the tooltip for the hop:
newTip = BaseMessages.getString(PKG, "PipelineGraph.Dialog.HopInfo") + Const.CR + BaseMessages.getString(PKG, "PipelineGraph.Dialog.HopInfo.SourceTransform") + " " + hi.getFromTransform().getName() + Const.CR + BaseMessages.getString(PKG, "PipelineGraph.Dialog.HopInfo.TargetTransform") + " " + hi.getToTransform().getName() + Const.CR + BaseMessages.getString(PKG, "PipelineGraph.Dialog.HopInfo.Status") + " " + (hi.isEnabled() ? BaseMessages.getString(PKG, "PipelineGraph.Dialog.HopInfo.Enable") : BaseMessages.getString(PKG, "PipelineGraph.Dialog.HopInfo.Disable"));
toolTip.setText(newTip);
showToolTip(new org.eclipse.swt.graphics.Point(screenX, screenY));
}
} else if (!newTip.equalsIgnoreCase(getToolTipText())) {
Image tooltipImage = null;
if (tipImage != null) {
tooltipImage = tipImage;
} else {
tooltipImage = GuiResource.getInstance().getImageHopUi();
}
showTooltip(newTip, tooltipImage, screenX, screenY);
}
return subject;
}
use of org.apache.hop.core.row.RowBuffer in project hop by apache.
the class PluginRegistryUnitTest method getGetPluginInformation.
@Test
public void getGetPluginInformation() throws HopPluginException {
PluginRegistry.getInstance().reset();
RowBuffer result = PluginRegistry.getInstance().getPluginInformation(BasePluginType.class);
assertNotNull(result);
assertEquals(10, result.getRowMeta().size());
for (IValueMeta vmi : result.getRowMeta().getValueMetaList()) {
assertEquals(IValueMeta.TYPE_STRING, vmi.getType());
}
}
use of org.apache.hop.core.row.RowBuffer in project hop by apache.
the class SniffTransformServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "PipelineStatusServlet.Log.SniffTransformRequested"));
}
String pipelineName = request.getParameter("pipeline");
String id = request.getParameter("id");
String transformName = request.getParameter("transform");
int copyNr = Const.toInt(request.getParameter("copynr"), 0);
final int nrLines = Const.toInt(request.getParameter("lines"), 0);
String type = Const.NVL(request.getParameter("type"), TYPE_OUTPUT);
boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
response.setStatus(HttpServletResponse.SC_OK);
if (useXML) {
response.setContentType("text/xml");
response.setCharacterEncoding(Const.XML_ENCODING);
} else {
response.setContentType("text/html;charset=UTF-8");
}
PrintWriter out = response.getWriter();
// ID is optional...
//
IPipelineEngine<PipelineMeta> pipeline;
HopServerObjectEntry entry;
if (Utils.isEmpty(id)) {
// get the first pipeline that matches...
//
entry = getPipelineMap().getFirstServerObjectEntry(pipelineName);
if (entry == null) {
pipeline = null;
} else {
id = entry.getId();
pipeline = getPipelineMap().getPipeline(entry);
}
} else {
// Take the ID into account!
//
entry = new HopServerObjectEntry(pipelineName, id);
pipeline = getPipelineMap().getPipeline(entry);
}
if (pipeline != null) {
// Find the transform to look at...
//
IEngineComponent component = null;
List<IEngineComponent> componentCopies = pipeline.getComponentCopies(transformName);
for (IEngineComponent componentCopy : componentCopies) {
if (componentCopy.getCopyNr() == copyNr) {
component = componentCopy;
}
}
final RowBuffer rowBuffer = new RowBuffer();
if (component != null) {
//
while (!(pipeline.isRunning() || pipeline.isReadyToStart()) && !pipeline.isStopped()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// ignore
}
}
if (!pipeline.isStopped()) {
// Add a listener to the pipeline transform...
//
final boolean read = type.equalsIgnoreCase(TYPE_INPUT);
final boolean written = type.equalsIgnoreCase(TYPE_OUTPUT) || !read;
IRowListener rowListener = new IRowListener() {
@Override
public void rowReadEvent(IRowMeta rowMeta, Object[] row) throws HopTransformException {
if (read && rowBuffer.getBuffer().size() < nrLines) {
rowBuffer.setRowMeta(rowMeta);
rowBuffer.getBuffer().add(row);
}
}
@Override
public void rowWrittenEvent(IRowMeta rowMeta, Object[] row) throws HopTransformException {
if (written && rowBuffer.getBuffer().size() < nrLines) {
rowBuffer.setRowMeta(rowMeta);
rowBuffer.getBuffer().add(row);
}
}
@Override
public void errorRowWrittenEvent(IRowMeta rowMeta, Object[] row) throws HopTransformException {
}
};
component.addRowListener(rowListener);
//
while (rowBuffer.getBuffer().size() < nrLines && component.isRunning() && !pipeline.isFinished() && !pipeline.isStopped()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
//
break;
}
}
// Remove the row listener
//
component.removeRowListener(rowListener);
}
//
if (useXML) {
// Send the result back as XML
//
response.setContentType("text/xml");
response.setCharacterEncoding(Const.XML_ENCODING);
out.print(XmlHandler.getXmlHeader(Const.XML_ENCODING));
out.println(rowBuffer.getXml());
} else {
response.setContentType("text/html;charset=UTF-8");
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>" + BaseMessages.getString(PKG, "SniffTransformServlet.SniffResults") + "</TITLE>");
out.println("<META http-equiv=\"Refresh\" content=\"10;url=" + convertContextPath(CONTEXT_PATH) + "?name=" + URLEncoder.encode(pipelineName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">");
out.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<H1>" + Encode.forHtml(BaseMessages.getString(PKG, "SniffTransformServlet.SniffResultsForTransform", transformName)) + "</H1>");
try {
out.println("<table border=\"1\">");
if (rowBuffer.getRowMeta() != null) {
// Print a header row containing all the field names...
//
out.print("<tr><th>#</th>");
for (IValueMeta valueMeta : rowBuffer.getRowMeta().getValueMetaList()) {
out.print("<th>" + valueMeta.getName() + "</th>");
}
out.println("</tr>");
//
for (int r = 0; r < rowBuffer.getBuffer().size(); r++) {
Object[] rowData = rowBuffer.getBuffer().get(r);
out.print("<tr>");
out.println("<td>" + (r + 1) + "</td>");
for (int v = 0; v < rowBuffer.getRowMeta().size(); v++) {
IValueMeta valueMeta = rowBuffer.getRowMeta().getValueMeta(v);
Object valueData = rowData[v];
out.println("<td>" + valueMeta.getString(valueData) + "</td>");
}
out.println("</tr>");
}
}
out.println("</table>");
out.println("<p>");
} catch (Exception ex) {
out.println("<p>");
out.println("<pre>");
out.println(Encode.forHtml(Const.getStackTracker(ex)));
out.println("</pre>");
}
out.println("<p>");
out.println("</BODY>");
out.println("</HTML>");
}
} else {
if (useXML) {
out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "SniffTransformServlet.Log.CoundNotFindSpecTransform", transformName)).getXml());
} else {
out.println("<H1>" + Encode.forHtml(BaseMessages.getString(PKG, "SniffTransformServlet.Log.CoundNotFindSpecTransform", transformName)) + "</H1>");
out.println("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "PipelineStatusServlet.BackToStatusPage") + "</a><p>");
}
}
} else {
if (useXML) {
out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "SniffTransformServlet.Log.CoundNotFindSpecPipeline", pipelineName)).getXml());
} else {
out.println("<H1>" + Encode.forHtml(BaseMessages.getString(PKG, "SniffTransformServlet.Log.CoundNotFindPipeline", pipelineName)) + "</H1>");
out.println("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "PipelineStatusServlet.BackToStatusPage") + "</a><p>");
}
}
}
Aggregations