use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.
the class WorkflowMeta method getAction.
/**
* Gets the action copy.
*
* @param x the x
* @param y the y
* @param iconsize the iconsize
* @return the action copy
*/
public ActionMeta getAction(int x, int y, int iconsize) {
int i;
int s;
s = nrActions();
for (i = s - 1; i >= 0; i--) {
// Back to front because drawing goes from start to end
ActionMeta action = getAction(i);
Point p = action.getLocation();
if (p != null) {
if (x >= p.x && x <= p.x + iconsize && y >= p.y && y <= p.y + iconsize) {
return action;
}
}
}
return null;
}
use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.
the class WorkflowMeta method getMaximum.
/**
* Gets the maximum.
*
* @return the maximum
*/
public Point getMaximum() {
int maxx = 0;
int maxy = 0;
for (int i = 0; i < nrActions(); i++) {
ActionMeta action = getAction(i);
Point loc = action.getLocation();
if (loc.x > maxx) {
maxx = loc.x;
}
if (loc.y > maxy) {
maxy = loc.y;
}
}
for (int i = 0; i < nrNotes(); i++) {
NotePadMeta ni = getNote(i);
Point loc = ni.getLocation();
if (loc.x + ni.width > maxx) {
maxx = loc.x + ni.width;
}
if (loc.y + ni.height > maxy) {
maxy = loc.y + ni.height;
}
}
return new Point(maxx + 100, maxy + 100);
}
use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.
the class WorkflowMeta method exportResources.
@Override
public String exportResources(IVariables variables, Map<String, ResourceDefinition> definitions, IResourceNaming namingInterface, IHopMetadataProvider metadataProvider) throws HopException {
String resourceName = null;
try {
// Handle naming for XML bases resources...
//
String baseName;
String originalPath;
String fullname;
String extension = "hwf";
if (StringUtils.isNotEmpty(getFilename())) {
FileObject fileObject = HopVfs.getFileObject(variables.resolve(getFilename()));
originalPath = fileObject.getParent().getName().getPath();
baseName = fileObject.getName().getBaseName();
fullname = fileObject.getName().getPath();
resourceName = namingInterface.nameResource(baseName, originalPath, extension, IResourceNaming.FileNamingType.WORKFLOW);
ResourceDefinition definition = definitions.get(resourceName);
if (definition == null) {
// If we do this once, it will be plenty :-)
//
WorkflowMeta workflowMeta = (WorkflowMeta) this.realClone(false);
// Set an appropriate name
//
workflowMeta.setNameSynchronizedWithFilename(false);
workflowMeta.setName(getName());
//
for (ActionMeta actionMeta : workflowMeta.workflowActions) {
actionMeta.getAction().exportResources(variables, definitions, namingInterface, metadataProvider);
}
// At the end, add ourselves to the map...
//
definition = new ResourceDefinition(resourceName, workflowMeta.getXml(variables));
//
if (Utils.isEmpty(this.getFilename())) {
definition.setOrigin(fullname);
} else {
definition.setOrigin(this.getFilename());
}
definitions.put(fullname, definition);
}
}
} catch (FileSystemException e) {
throw new HopException(BaseMessages.getString(PKG, "WorkflowMeta.Exception.AnErrorOccuredReadingWorkflow", getFilename()), e);
} catch (HopFileException e) {
throw new HopException(BaseMessages.getString(PKG, "WorkflowMeta.Exception.AnErrorOccuredReadingWorkflow", getFilename()), e);
}
return resourceName;
}
use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.
the class LocalWorkflowEngine method startExecution.
@Override
public Result startExecution() {
if (!(workflowRunConfiguration.getEngineRunConfiguration() instanceof LocalWorkflowRunConfiguration)) {
log.logError("Error starting workflow", new HopException("A local workflow execution expects a local workflow configuration, not an instance of class " + workflowRunConfiguration.getEngineRunConfiguration().getClass().getName()));
result = new Result();
result.setNrErrors(1L);
return result;
}
LocalWorkflowRunConfiguration config = (LocalWorkflowRunConfiguration) workflowRunConfiguration.getEngineRunConfiguration();
// See if we need to enable transactions...
//
IExtensionData parentExtensionData = getParentPipeline();
if (parentExtensionData == null) {
parentExtensionData = getParentWorkflow();
}
String connectionGroup = null;
if (parentExtensionData != null && parentExtensionData.getExtensionDataMap() != null) {
connectionGroup = (String) parentExtensionData.getExtensionDataMap().get(Const.CONNECTION_GROUP);
}
//
if (config.isTransactional() && connectionGroup == null) {
// Store a value in the parent...
//
connectionGroup = getWorkflowMeta().getName() + " - " + UUID.randomUUID();
// We also need to commit/rollback at the end of this workflow...
//
addWorkflowFinishedListener(workflow -> {
String group = (String) workflow.getExtensionDataMap().get(Const.CONNECTION_GROUP);
List<Database> databases = DatabaseConnectionMap.getInstance().getDatabases(group);
Result result = workflow.getResult();
for (Database database : databases) {
//
try {
if (result.getResult() && !result.isStopped() && result.getNrErrors() == 0) {
try {
database.commit(true);
workflow.getLogChannel().logBasic("All transactions of database connection '" + database.getDatabaseMeta().getName() + "' were committed at the end of the workflow!");
} catch (HopDatabaseException e) {
workflow.getLogChannel().logError("Error committing database connection " + database.getDatabaseMeta().getName(), e);
result.setNrErrors(result.getNrErrors() + 1);
}
} else {
// Error? Rollback!
try {
database.rollback(true);
workflow.getLogChannel().logBasic("All transactions of database connection '" + database.getDatabaseMeta().getName() + "' were rolled back at the end of the workflow!");
} catch (HopDatabaseException e) {
workflow.getLogChannel().logError("Error rolling back database connection " + database.getDatabaseMeta().getName(), e);
result.setNrErrors(result.getNrErrors() + 1);
}
}
} finally {
// Always close connection!
try {
database.closeConnectionOnly();
workflow.getLogChannel().logDebug("Database connection '" + database.getDatabaseMeta().getName() + "' closed successfully!");
} catch (HopDatabaseException hde) {
workflow.getLogChannel().logError("Error disconnecting from database - closeConnectionOnly failed:" + Const.CR + hde.getMessage());
workflow.getLogChannel().logError(Const.getStackTracker(hde));
}
// Definitely remove the connection reference the connections map
DatabaseConnectionMap.getInstance().removeConnection(group, null, database);
}
}
});
}
//
if (connectionGroup != null && getExtensionDataMap() != null) {
// Set the connection group for this workflow
//
getExtensionDataMap().put(Const.CONNECTION_GROUP, connectionGroup);
}
// Pass down the value of the connection group value to actions before they're executed...
//
addActionListener(new IActionListener() {
@Override
public void beforeExecution(IWorkflowEngine workflow, ActionMeta actionMeta, IAction action) {
String connectionGroup = (String) workflow.getExtensionDataMap().get(Const.CONNECTION_GROUP);
if (connectionGroup != null) {
action.getExtensionDataMap().put(Const.CONNECTION_GROUP, connectionGroup);
}
}
@Override
public void afterExecution(IWorkflowEngine workflow, ActionMeta actionMeta, IAction action, Result result) {
// Nothing
}
});
return super.startExecution();
}
use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.
the class WorkflowMetaTest method testHasLoop_simpleLoop.
@Test
public void testHasLoop_simpleLoop() throws Exception {
// main->2->3->main
WorkflowMeta workflowMetaSpy = spy(workflowMeta);
ActionMeta actionCopyMain = createAction("mainTransform");
ActionMeta actionCopy2 = createAction("transform2");
ActionMeta actionCopy3 = createAction("transform3");
when(workflowMetaSpy.findNrPrevActions(actionCopyMain)).thenReturn(1);
when(workflowMetaSpy.findPrevAction(actionCopyMain, 0)).thenReturn(actionCopy2);
when(workflowMetaSpy.findNrPrevActions(actionCopy2)).thenReturn(1);
when(workflowMetaSpy.findPrevAction(actionCopy2, 0)).thenReturn(actionCopy3);
when(workflowMetaSpy.findNrPrevActions(actionCopy3)).thenReturn(1);
when(workflowMetaSpy.findPrevAction(actionCopy3, 0)).thenReturn(actionCopyMain);
assertTrue(workflowMetaSpy.hasLoop(actionCopyMain));
}
Aggregations