Search in sources :

Example 1 with JdbcResourceInfo

use of org.pentaho.metaverse.api.model.JdbcResourceInfo in project pentaho-metaverse by pentaho.

the class ModelSerializationIT method testSerializeDeserialize.

@Test
public void testSerializeDeserialize() throws Exception {
    String server = "localhost";
    String dbName = "test";
    int port = 9999;
    String user = "testUser";
    String password = "password";
    JdbcResourceInfo jdbcResource = new JdbcResourceInfo(server, dbName, port, user, password);
    jdbcResource.setInput(true);
    String json = mapper.writeValueAsString(jdbcResource);
    // System.out.println( json );
    JdbcResourceInfo rehydrated = mapper.readValue(json, JdbcResourceInfo.class);
    assertEquals(jdbcResource.getServer(), rehydrated.getServer());
    assertEquals(jdbcResource.getDatabaseName(), rehydrated.getDatabaseName());
    assertEquals(jdbcResource.getUsername(), rehydrated.getUsername());
    assertEquals(jdbcResource.getPassword(), rehydrated.getPassword());
    assertEquals(jdbcResource.getPort(), rehydrated.getPort());
    assertEquals(jdbcResource.isInput(), rehydrated.isInput());
    ExecutionProfile executionProfile = new ExecutionProfile("run1", "some/path/to/a.ktl", "tranformation", "A test profile");
    long currentMillis = System.currentTimeMillis();
    long futureMillis = currentMillis + 10000;
    Timestamp startTime = new Timestamp(currentMillis);
    Timestamp endTime = new Timestamp(futureMillis);
    executionProfile.getExecutionData().setStartTime(startTime);
    executionProfile.getExecutionData().setEndTime(endTime);
    executionProfile.getExecutionData().setClientExecutor("client.executer");
    executionProfile.getExecutionData().setExecutorServer("www.pentaho.com");
    executionProfile.getExecutionData().setExecutorUser("wseyler");
    executionProfile.getExecutionData().setLoggingChannelId("kettle.debug");
    executionProfile.getExecutionData().addParameter(new ParamInfo("testParam1", "Larry", "Fine", "A Test Parameter"));
    executionProfile.getExecutionData().addParameter(new ParamInfo("testParam2", "Howard", "Moe", "Another Parameter"));
    executionProfile.getExecutionData().addParameter(new ParamInfo("testParam3", "Fine", "Curly", "A Third Parameter"));
    String externalResourceName = "prices.csv";
    String externalResourceDescription = "A test csv file";
    String externalResourceType = "csv";
    String attributeName = "hair";
    String attributeValue = "red";
    BaseResourceInfo externalResourceInfo = new BaseResourceInfo();
    externalResourceInfo.setName(externalResourceName);
    externalResourceInfo.setDescription(externalResourceDescription);
    externalResourceInfo.setInput(true);
    externalResourceInfo.setType(externalResourceType);
    externalResourceInfo.putAttribute(attributeName, attributeValue);
    executionProfile.getExecutionData().addExternalResource("testStep", externalResourceInfo);
    String variable1Name = "area";
    String variable1Value = "West";
    String variable2Name = "dept";
    String variable2Value = "Sales";
    executionProfile.getExecutionData().addVariable(variable1Name, variable1Value);
    executionProfile.getExecutionData().addVariable(variable2Name, variable2Value);
    String arg1 = "You're stupid";
    String arg2 = "You're ugly";
    String arg3 = "You're lazy";
    executionProfile.getExecutionData().putArgument(0, arg1);
    executionProfile.getExecutionData().putArgument(1, arg2);
    executionProfile.getExecutionData().putArgument(2, arg3);
    json = mapper.writeValueAsString(executionProfile);
    // System.out.println( json );
    ExecutionProfile rehydratedProfile = mapper.readValue(json, ExecutionProfile.class);
    assertEquals(executionProfile.getName(), rehydratedProfile.getName());
    assertEquals(executionProfile.getPath(), rehydratedProfile.getPath());
    assertEquals(executionProfile.getType(), rehydratedProfile.getType());
    assertEquals(executionProfile.getDescription(), rehydratedProfile.getDescription());
    assertEquals(executionProfile.getExecutionData().getStartTime().compareTo(rehydratedProfile.getExecutionData().getStartTime()), 0);
    assertEquals(executionProfile.getExecutionData().getEndTime().compareTo(rehydratedProfile.getExecutionData().getEndTime()), 0);
    assertEquals(executionProfile.getExecutionData().getFailureCount(), 0);
    assertEquals(executionProfile.getExecutionData().getClientExecutor(), rehydratedProfile.getExecutionData().getClientExecutor());
    assertEquals(executionProfile.getExecutionData().getExecutorServer(), rehydratedProfile.getExecutionData().getExecutorServer());
    assertEquals(executionProfile.getExecutionData().getExecutorUser(), rehydratedProfile.getExecutionData().getExecutorUser());
    assertEquals(executionProfile.getExecutionData().getLoggingChannelId(), rehydratedProfile.getExecutionData().getLoggingChannelId());
    assertEquals(rehydratedProfile.getExecutionData().getParameters().size(), 3);
    assertEquals(rehydratedProfile.getExecutionData().getExternalResources().size(), 1);
    Map<Object, Object> attributes = rehydratedProfile.getExecutionData().getExternalResources().get("testStep").get(0).getAttributes();
    assertEquals(attributes.get(attributeName), attributeValue);
    assertEquals(executionProfile.getExecutionData().getVariables().size(), 2);
    assertTrue(executionProfile.getExecutionData().getVariables().containsKey(variable1Name));
    assertTrue(executionProfile.getExecutionData().getVariables().containsKey(variable2Name));
    assertTrue(executionProfile.getExecutionData().getVariables().containsValue(variable1Value));
    assertTrue(executionProfile.getExecutionData().getVariables().containsValue(variable2Value));
    assertEquals(executionProfile.getExecutionData().getArguments().get(0), arg1);
    assertEquals(executionProfile.getExecutionData().getArguments().get(1), arg2);
    assertEquals(executionProfile.getExecutionData().getArguments().get(2), arg3);
}
Also used : BaseResourceInfo(org.pentaho.metaverse.api.model.BaseResourceInfo) JdbcResourceInfo(org.pentaho.metaverse.api.model.JdbcResourceInfo) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 2 with JdbcResourceInfo

use of org.pentaho.metaverse.api.model.JdbcResourceInfo in project pentaho-metaverse by pentaho.

the class TransMetaJsonDeserializerTest method testDeserializeConnections.

@Test
public void testDeserializeConnections() throws Exception {
    JndiResourceInfo jndi = new JndiResourceInfo("jndi");
    jndi.setPluginId("ORACLE");
    JdbcResourceInfo jdbc = new JdbcResourceInfo("localhost", "test", 5432, "sa", "password");
    jdbc.setPluginId("POSTGRESQL");
    transMeta = spy(new TransMeta());
    root_connectionsArray.add(root_connectionsArray_Node0);
    root_connectionsArray.add(root_connectionsArray_Node1);
    when(root_connectionsArray_Node0.toString()).thenReturn("mocked jdbc");
    when(root_connectionsArray_Node0.get(IInfo.JSON_PROPERTY_CLASS)).thenReturn(root_connectionsArray_Node0_classNode);
    when(root_connectionsArray_Node0_classNode.asText()).thenReturn(JdbcResourceInfo.class.getName());
    when(root_connectionsArray_Node1.toString()).thenReturn("mocked jndi");
    when(root_connectionsArray_Node1.get(IInfo.JSON_PROPERTY_CLASS)).thenReturn(root_connectionsArray_Node1_classNode);
    when(root_connectionsArray_Node1_classNode.asText()).thenReturn(JndiResourceInfo.class.getName());
    when(mapper.readValue("mocked jdbc", JdbcResourceInfo.class)).thenReturn(jdbc);
    when(mapper.readValue("mocked jndi", JndiResourceInfo.class)).thenReturn(jndi);
    deserializer.deserializeConnections(transMeta, root, mapper);
    assertEquals(root_connectionsArray.size(), transMeta.getDatabases().size());
    for (DatabaseMeta databaseMeta : transMeta.getDatabases()) {
        assertNotNull(databaseMeta.getDatabaseInterface());
    }
}
Also used : JdbcResourceInfo(org.pentaho.metaverse.api.model.JdbcResourceInfo) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) JndiResourceInfo(org.pentaho.metaverse.api.model.JndiResourceInfo) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 3 with JdbcResourceInfo

use of org.pentaho.metaverse.api.model.JdbcResourceInfo in project pentaho-metaverse by pentaho.

the class TransMetaJsonDeserializer method deserializeConnections.

protected void deserializeConnections(TransMeta transMeta, JsonNode node, ObjectMapper mapper) {
    ArrayNode connectionsArrayNode = (ArrayNode) node.get(TransMetaJsonSerializer.JSON_PROPERTY_CONNECTIONS);
    IExternalResourceInfo conn = null;
    for (int i = 0; i < connectionsArrayNode.size(); i++) {
        JsonNode connNode = connectionsArrayNode.get(i);
        String className = connNode.get(IInfo.JSON_PROPERTY_CLASS).asText();
        try {
            Class clazz = this.getClass().getClassLoader().loadClass(className);
            conn = (IExternalResourceInfo) clazz.newInstance();
            conn = mapper.readValue(connNode.toString(), conn.getClass());
            DatabaseMeta dbMeta = null;
            if (conn instanceof JdbcResourceInfo) {
                JdbcResourceInfo db = (JdbcResourceInfo) conn;
                dbMeta = new DatabaseMeta(db.getName(), db.getPluginId(), DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_NATIVE), db.getServer(), db.getDatabaseName(), String.valueOf(db.getPort()), db.getUsername(), db.getPassword());
            } else if (conn instanceof JndiResourceInfo) {
                JndiResourceInfo db = (JndiResourceInfo) conn;
                dbMeta = new DatabaseMeta(db.getName(), db.getPluginId(), DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_JNDI), null, null, null, null, null);
            }
            transMeta.addDatabase(dbMeta);
        } catch (Exception e) {
            LOGGER.warn(Messages.getString("WARNING.Deserialization.Trans.Connections", conn.getName(), transMeta.getName()), e);
        }
    }
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) JdbcResourceInfo(org.pentaho.metaverse.api.model.JdbcResourceInfo) JsonNode(com.fasterxml.jackson.databind.JsonNode) JndiResourceInfo(org.pentaho.metaverse.api.model.JndiResourceInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Aggregations

JdbcResourceInfo (org.pentaho.metaverse.api.model.JdbcResourceInfo)3 Test (org.junit.Test)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 JndiResourceInfo (org.pentaho.metaverse.api.model.JndiResourceInfo)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 KettleException (org.pentaho.di.core.exception.KettleException)1 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)1 TransMeta (org.pentaho.di.trans.TransMeta)1 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)1 BaseResourceInfo (org.pentaho.metaverse.api.model.BaseResourceInfo)1 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)1