@Test
  public void testDDLExport() throws Exception {
    String vdbName = "test";
    String testVDB =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"test\" version=\"1\">\n"
            + "    <property name=\"UseConnectorMetadata\" value=\"cached\" />\n"
            + "    <model name=\"loopy\">\n"
            + "        <source name=\"loop\" translator-name=\"loopy\" />\n"
            + "    </model>\n"
            + "</vdb>";

    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    JavaArchive jar = getLoopyArchive();
    admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());

    // normal load
    admin.deploy("test-vdb.xml", new ByteArrayInputStream(testVDB.getBytes()));
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);

    String ddl = admin.getSchema(vdbName, 1, "loopy", null, null);

    String expected = "CREATE FOREIGN TABLE Matadata (\n" + "	execCount integer\n" + ");";
    assertEquals(expected, ddl);

    admin.undeploy("loopy.jar");
  }
  public void testGetDatasourceProperties() throws Exception {
    Properties props = new Properties();
    props.setProperty("connection-url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    props.setProperty("user-name", "sa");
    props.setProperty("password", "sa");
    props.setProperty("connection-properties", "foo=bar,blah=blah");
    props.setProperty("max-pool-size", "4");

    admin.createDataSource("Oracle11_PushDS", "h2", props);

    Properties p = admin.getDataSource("Oracle11_PushDS");
    assertEquals("4", p.getProperty("max-pool-size"));
    assertEquals("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", p.getProperty("connection-url"));

    admin.deleteDataSource("Oracle11_PushDS");

    p = new Properties();
    p.setProperty("class-name", "org.teiid.resource.adapter.ws.WSManagedConnectionFactory");
    p.setProperty("EndPoint", "{endpoint}");
    props.setProperty("max-pool-size", "4");
    admin.createDataSource("nowhere", "teiid-connector-ws.rar", p);

    assertEquals(
        "org.teiid.resource.adapter.ws.WSManagedConnectionFactory", p.getProperty("class-name"));
    assertEquals("4", p.getProperty("max-pool-size"));
    assertEquals("{endpoint}", p.getProperty("EndPoint"));

    admin.deleteDataSource("nowhere");
  }
Ejemplo n.º 3
0
  // TEIID-3914 - test the olingo-patch work
  public void testCompositeKeyTimestamp() throws Exception {

    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"northwind\" version=\"1\">\n"
            + "    <model name=\"m\">\n"
            + "        <source name=\"x1\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE x (a string, b timestamp, c integer, primary key (a, b)) options (updatable true);\n"
            + "        ]]> </metadata>\n"
            + "    </model>\n"
            + "</vdb>";

    admin.deploy(
        "loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));
    assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

    WebClient client =
        WebClient.create("http://localhost:8080/odata4/m/x(a='a',b=2011-09-11T00:00:00Z)");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    Response response = client.invoke("GET", null);
    assertEquals(200, response.getStatus());

    client = WebClient.create("http://localhost:8080/odata4/m/x");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    response = client.post("{\"a\":\"b\", \"b\":\"2000-02-02T22:22:22Z\"}");
    assertEquals(204, response.getStatus());

    admin.undeploy("loopy-vdb.xml");
  }
  @Test
  public void getTemplatePropertyDefinitions() throws Exception {
    HashSet<String> props = new HashSet<String>();

    deployVdb();

    Collection<? extends PropertyDefinition> pds = admin.getTemplatePropertyDefinitions("h2");
    for (PropertyDefinition pd : pds) {
      props.add(pd.getName());
    }
    assertTrue(props.contains("connection-url"));
    assertTrue(props.contains("user-name"));
    assertTrue(props.contains("password"));
    assertTrue(props.contains("check-valid-connection-sql"));
    assertTrue(props.contains("max-pool-size"));
    assertTrue(props.contains("connection-properties"));
    assertTrue(props.contains("max-pool-size"));

    HashSet<String> rar_props = new HashSet<String>();
    pds = admin.getTemplatePropertyDefinitions("file");
    for (PropertyDefinition pd : pds) {
      rar_props.add(pd.getName());
    }

    assertTrue(rar_props.contains("ParentDirectory"));
    assertTrue(rar_props.contains("FileMapping"));
    assertTrue(rar_props.contains("AllowParentPaths"));
    assertTrue(rar_props.contains("resourceadapter-class"));
    assertTrue(rar_props.contains("managedconnectionfactory-class"));
    assertTrue(rar_props.contains("max-pool-size"));
  }
Ejemplo n.º 5
0
  @Test
  public void testOdata() throws Exception {
    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"Loopy\" version=\"1\">\n"
            + "    <model name=\"MarketData\">\n"
            + "        <source name=\"text-connector2\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE G1 (e1 string, e2 integer PRIMARY KEY);\n"
            + "                CREATE FOREIGN TABLE G2 (e1 string, e2 integer PRIMARY KEY) OPTIONS (UPDATABLE 'true');\n"
            + "        ]]> </metadata>\n"
            + "    </model>\n"
            + "</vdb>";

    admin.deploy(
        "loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));

    assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

    WebClient client =
        WebClient.create("http://*****:*****@mm://localhost:31000;user=user;password=user", null);

    PreparedStatement ps =
        conn.prepareCall(
            "select t.* from xmltable('/*:Edmx/*:DataServices/*:Schema[@Alias=\"MarketData\"]' passing xmlparse(document cast(? as clob))) as t");
    ps.setAsciiStream(1, (InputStream) response.getEntity());

    ResultSet rs = ps.executeQuery();
    rs.next();

    assertEquals(
        ObjectConverterUtil.convertFileToString(
            UnitTestUtil.getTestDataFile("loopy-metadata4-results.txt")),
        rs.getString(1));

    conn.close();

    // try an invalid url
    client = WebClient.create("http://localhost:8080/odata/x/y$metadata");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    response = client.invoke("GET", null);
    assertEquals(500, response.getStatus());

    admin.undeploy("loopy-vdb.xml");
  }
Ejemplo n.º 6
0
  @Test
  public void testReadOdataMetadata() throws Exception {
    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"Loopy\" version=\"1\">\n"
            + "    <model name=\"MarketData\">\n"
            + "        <source name=\"text-connector2\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE G1 (e1 string[], e2 integer PRIMARY KEY);\n"
            + "                CREATE FOREIGN TABLE G2 (e1 string, e2 integer PRIMARY KEY) OPTIONS (UPDATABLE 'true');\n"
            + "        ]]> </metadata>\n"
            + "    </model>\n"
            + "</vdb>";

    admin.deploy(
        "loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));

    assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

    String vdb2 =
        "<?xml version='1.0' encoding='UTF-8'?>\n"
            + "<vdb name=\"TestOData\" version=\"1\">\n"
            + "    <model name=\"TestOData\" type=\"PHYSICAL\" visible=\"true\">\n"
            + "     <property name=\"importer.entityContainer\" value=\"MarketData\"/>\n"
            + "     <property name=\"importer.schemaNamespace\" value=\"MarketData\"/>\n"
            + "     <source name=\"TestOData\" translator-name=\"odata4\" connection-jndi-name=\"java:/TestOData4\"/>\n"
            + "    </model>\n"
            + "</vdb>";

    Properties p = new Properties();
    p.setProperty("class-name", "org.teiid.resource.adapter.ws.WSManagedConnectionFactory");
    p.setProperty("EndPoint", "http://*****:*****@mm://localhost:31000;user=user;password=user", null);

    execute("SELECT Name FROM Sys.Tables Where name='G1'"); // $NON-NLS-1$
    assertResultsSetEquals("Name[string]\nG1");

    execute("SELECT * from G1"); // $NON-NLS-1$
    assertResultsSetEquals("e1[string[]]    e2[integer]\n[ABCDEFGHIJ]    0");

    admin.undeploy("loopy-vdb.xml");
    admin.undeploy("test-vdb.xml");
  }
  private boolean deployVdb() throws AdminException, FileNotFoundException {
    boolean vdbOneDeployed;
    admin.deploy("bqt.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt.vdb")));
    AdminUtil.waitForVDBLoad(admin, "bqt", 1, 3);
    vdbOneDeployed = true;

    VDB vdb = admin.getVDB("bqt", 1);
    Model model = vdb.getModels().get(0);
    admin.assignToModel(
        "bqt", 1, model.getName(), "Source", "h2", "java:jboss/datasources/ExampleDS");
    return vdbOneDeployed;
  }
  @Test
  public void testErrorDeployment() throws Exception {
    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    admin.deploy(
        "error-vdb.xml", new FileInputStream(UnitTestUtil.getTestDataFile("error-vdb.xml")));

    AdminUtil.waitForVDBLoad(admin, "error", 1, 3);
    VDB vdb = admin.getVDB("error", 1);
    assertEquals(Status.FAILED, vdb.getStatus());
  }
  @Test
  public void testDataRoleMapping() throws Exception {
    admin.deploy("bqt2.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt2.vdb")));

    VDB vdb = admin.getVDB("bqt", 2);
    Model model = vdb.getModels().get(0);
    admin.assignToModel(
        "bqt", 2, model.getName(), "Source", "h2", "java:jboss/datasources/ExampleDS");

    vdb = admin.getVDB("bqt", 2);
    assertTrue(vdb.isValid());
    List<DataPolicy> policies = vdb.getDataPolicies();
    assertEquals(1, policies.size());

    DataPolicy dp = policies.get(0);
    assertEquals("roleOne", dp.getName());
    assertEquals(2, dp.getPermissions().size());
    assertTrue(dp.isAllowCreateTemporaryTables());
    assertTrue(dp.isAnyAuthenticated());

    List<String> roleNames = dp.getMappedRoleNames();
    assertArrayEquals(new String[] {"ROLE1", "ROLE2"}, roleNames.toArray());

    admin.removeDataRoleMapping("bqt", 2, "roleOne", "ROLE1");

    vdb = admin.getVDB("bqt", 2);
    policies = vdb.getDataPolicies();
    dp = policies.get(0);

    roleNames = dp.getMappedRoleNames();
    assertArrayEquals(new String[] {"ROLE2"}, roleNames.toArray());

    admin.addDataRoleMapping("bqt", 2, "roleOne", "ROLE3");

    vdb = admin.getVDB("bqt", 2);
    policies = vdb.getDataPolicies();
    dp = policies.get(0);

    roleNames = dp.getMappedRoleNames();
    assertArrayEquals(new String[] {"ROLE2", "ROLE3"}, roleNames.toArray());

    admin.setAnyAuthenticatedForDataRole("bqt", 2, "roleOne", false);

    vdb = admin.getVDB("bqt", 2);
    policies = vdb.getDataPolicies();
    dp = policies.get(0);

    assertFalse(dp.isAnyAuthenticated());
  }
  @Test
  public void testVDBConnectionType() throws Exception {
    admin.deploy("bqt.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt.vdb")));

    VDB vdb = admin.getVDB("bqt", 1);
    Model model = vdb.getModels().get(0);
    admin.updateSource("bqt", 1, "Source", "h2", "java:jboss/datasources/ExampleDS");

    try {
      // should not be able to remove from non-multisource
      admin.removeSource("bqt", 1, model.getName(), "Source");
      fail();
    } catch (AdminException e) {

    }

    assertEquals(ConnectionType.BY_VERSION, vdb.getConnectionType());

    Connection conn =
        TeiidDriver.getInstance()
            .connect("jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user", null);
    conn.close();

    admin.changeVDBConnectionType("bqt", 1, ConnectionType.NONE);

    try {
      TeiidDriver.getInstance()
          .connect("jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user", null);
      fail("should have failed to connect as no new connections allowed");
    } catch (Exception e) {
      // pass
    }

    admin.deploy("bqt2.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt2.vdb")));
    admin.updateSource("bqt", 2, "Source", "h2", "java:jboss/datasources/ExampleDS");

    conn =
        TeiidDriver.getInstance()
            .connect("jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user", null);
    conn.close();

    admin.changeVDBConnectionType("bqt", 2, ConnectionType.ANY);
    conn =
        TeiidDriver.getInstance()
            .connect("jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user", null);
    conn.close();

    vdb = admin.getVDB("bqt", 2);
    model = vdb.getModels().get(0);
    assertEquals(model.getSourceConnectionJndiName("Source"), "java:jboss/datasources/ExampleDS");
    assertEquals(model.getSourceTranslatorName("Source"), "h2");
    assertEquals(ConnectionType.ANY, vdb.getConnectionType());
  }
 @Test
 public void getDatasourceTemplateNames() throws Exception {
   Set<String> vals =
       new HashSet<String>(
           Arrays.asList(
               new String[] {
                 "teiid-local",
                 "google",
                 "teiid",
                 "ldap",
                 "accumulo",
                 "infinispan",
                 "file",
                 "cassandra",
                 "salesforce",
                 "mongodb",
                 "solr",
                 "webservice",
                 "simpledb",
                 "h2"
               }));
   deployVdb();
   Set<String> templates = admin.getDataSourceTemplateNames();
   assertEquals(vals, templates);
 }
  @Test
  public void testChainedDelegates() throws Exception {
    Properties props = new Properties();
    props.setProperty("connection-url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    props.setProperty("user-name", "sa");
    props.setProperty("password", "sa");

    AdminUtil.createDataSource(admin, "Oracle11_PushDS", "h2", props);
    admin.deploy("fake.jar", new FileInputStream(UnitTestUtil.getTestDataFile("fake.jar")));
    try {
      admin.deploy(
          "chained-vdb.xml", new FileInputStream(UnitTestUtil.getTestDataFile("chained-vdb.xml")));
    } finally {
      admin.undeploy("fake.jar");
    }
  }
  @Test
  public void getTranslatorPropertyDefinitions() throws Exception {
    HashSet<String> props = new HashSet<String>();

    Collection<? extends PropertyDefinition> pds = admin.getTranslatorPropertyDefinitions("ws");
    for (PropertyDefinition pd : pds) {
      props.add(pd.getName());
    }
    assertTrue(props.contains("DefaultBinding"));
    assertTrue(props.contains("DefaultServiceMode"));
    assertTrue(props.contains("MaxDependentInPredicates"));

    for (PropertyDefinition pd : pds) {
      if (pd.getName().equals("DefaultBinding")) {
        assertEquals("java.lang.String", pd.getPropertyTypeClassName());
        assertFalse(pd.isRequired());
        assertEquals(
            "Contols what SOAP or HTTP type of invocation will be used if none is specified.",
            pd.getDescription());
        assertEquals("Default Binding", pd.getDisplayName());
        assertTrue(pd.isModifiable());
        assertFalse(pd.isAdvanced());
        assertFalse(pd.isMasked());
        assertEquals("SOAP12", pd.getDefaultValue());
        assertNotNull(pd.getAllowedValues());
      }
    }
  }
  @Test
  public void testGetRequests() throws Exception {
    JavaArchive jar = getLoopyArchive();

    try {
      admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());
      deployVdb();
      Translator t = admin.getTranslator("loopy");
      assertNotNull(t);

      admin.updateSource("bqt", 1, "Source", "loopy", "java:jboss/datasources/ExampleDS");
      Connection conn =
          TeiidDriver.getInstance()
              .connect("jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user", null);
      Collection<? extends Session> sessions = admin.getSessions();
      assertEquals(1, sessions.size());
      Session s = sessions.iterator().next();

      Statement stmt = conn.createStatement();

      Collection<? extends Request> requests = admin.getRequests();

      assertEquals(0, requests.size());

      stmt.execute("select * from source.smalla");

      requests = admin.getRequests();
      assertEquals(1, requests.size());

      Request r = requests.iterator().next();
      assertEquals("select * from source.smalla", r.getCommand());
      assertNotNull(r.getExecutionId());
      assertNotNull(r.getSessionId());

      stmt.execute("select * from source.smalla");
      Collection<? extends Request> requests2 = admin.getRequestsForSession(s.getSessionId());
      assertEquals(1, requests2.size());

      Request r2 = requests.iterator().next();
      assertEquals("select * from source.smalla", r2.getCommand());
      assertEquals(s.getSessionId(), r2.getSessionId());

      stmt.close();
      conn.close();

      requests = admin.getRequests();
      assertEquals(0, requests.size());

    } finally {
      admin.undeploy("loopy.jar");
    }
  }
 @Test
 public void testCacheTypes() throws Exception {
   String[] array = {
     Admin.Cache.PREPARED_PLAN_CACHE.toString(),
     Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString()
   };
   Collection<String> types = admin.getCacheTypes();
   assertArrayEquals(array, types.toArray());
 }
 @Test
 public void testODBCConnectionSuccess() throws Exception {
   admin.deploy("bqt.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt.vdb")));
   Driver d = new Driver();
   Properties p = new Properties();
   p.setProperty("user", "user");
   p.setProperty("password", "user");
   Connection c = d.connect("jdbc:postgresql://127.0.0.1:35432/bqt", p);
   c.close();
 }
  @Test
  public void testTraslators() throws Exception {
    Collection<? extends Translator> translators = admin.getTranslators();
    assertEquals(38, translators.size());

    JavaArchive jar = getLoopyArchive();

    try {
      admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());

      VDBTranslatorMetaData t = (VDBTranslatorMetaData) admin.getTranslator("loopy");
      assertNotNull(t);
      assertEquals("ANY", t.getPropertyValue("SupportedJoinCriteria"));
      assertEquals("true", t.getPropertyValue("supportsSelectDistinct"));
    } finally {
      admin.undeploy("loopy.jar");
    }

    VDBTranslatorMetaData t = (VDBTranslatorMetaData) admin.getTranslator("orcl");
    assertNull(t);
  }
  @Test
  public void testVDBRestart() throws Exception {
    String vdbName = "test";
    String testVDB =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"test\" version=\"1\">\n"
            + "    <property name=\"UseConnectorMetadata\" value=\"cached\" />\n"
            + "    <model name=\"loopy\">\n"
            + "        <source name=\"loop\" translator-name=\"loopy\" />\n"
            + "    </model>\n"
            + "</vdb>";

    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    JavaArchive jar = getLoopyArchive();
    admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());

    // normal load
    admin.deploy("test-vdb.xml", new ByteArrayInputStream(testVDB.getBytes()));
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
    int count = assertMetadataLoadCount(false, 1);

    // 1st restart
    admin.restartVDB(vdbName, 1);
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
    count = assertMetadataLoadCount(true, count + 1);

    // 2nd restart
    admin.restartVDB(vdbName, 1);
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
    count = assertMetadataLoadCount(true, count + 1);

    admin.undeploy("loopy.jar");
  }
  @Test
  public void testSystemPropertiesInVDBXML() throws Exception {
    String vdbName = "test";
    String testVDB =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"test\" version=\"1\">\n"
            + "    <property name=\"UseConnectorMetadata\" value=\"${teiid.vdb.UseConnectorMetadata:none}\" />\n"
            + "    <model name=\"loopy\">\n"
            + "        <source name=\"loop\" translator-name=\"loopy\" />\n"
            + "    </model>\n"
            + "</vdb>";

    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    JavaArchive jar = getLoopyArchive();
    admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());

    // normal load
    admin.deploy("test-vdb.xml", new ByteArrayInputStream(testVDB.getBytes()));
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);

    VDB vdb = admin.getVDB(vdbName, 1);
    String value = vdb.getPropertyValue("UseConnectorMetadata");

    // see the arquillian.zml file in resources in the JVM proeprties section for the expected value
    assertEquals("custom", value);

    admin.undeploy("loopy.jar");
    admin.undeploy("test-vdb.xml");
  }
 @Test
 public void testODBCConnectionFailure() throws Exception {
   admin.deploy("bqt.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt.vdb")));
   Driver d = new Driver();
   Properties p = new Properties();
   p.setProperty("user", "user");
   p.setProperty("password", "notpassword");
   try {
     d.connect("jdbc:postgresql://127.0.0.1:35432/bqt", p);
     fail("failed due to bad credentials");
   } catch (SQLException e) {
   }
 }
Ejemplo n.º 21
0
  private IStatus pingJdbc() {
    String host = teiidServer.getHost();
    ITeiidJdbcInfo teiidJdbcInfo = teiidServer.getTeiidJdbcInfo();

    Connection teiidJdbcConnection = null;
    String url = "jdbc:teiid:ping@mm://" + host + ':' + teiidJdbcInfo.getPort(); // $NON-NLS-1$

    try {
      admin.deployVDB(
          "ping-vdb.xml",
          (InputStream) new ByteArrayInputStream(TEST_VDB.getBytes())); // $NON-NLS-1$
      try {
        String urlAndCredentials =
            url
                + ";user="******";password="******"ping", 1); // $NON-NLS-1$

        if (teiidJdbcConnection != null) {
          teiidJdbcConnection.close();
        }
      }
    } catch (Exception ex) {
      String msg = NLS.bind(Messages.serverDeployUndeployProblemPingingTeiidJdbc, url);
      return new Status(IStatus.ERROR, PLUGIN_ID, msg, ex);
    }

    return Status.OK_STATUS;
  }
  @Test
  public void testSessions() throws Exception {
    deployVdb();

    Collection<? extends Session> sessions = admin.getSessions();
    assertEquals(0, sessions.size());

    Connection conn =
        TeiidDriver.getInstance()
            .connect(
                "jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user;ApplicationName=test",
                null);
    sessions = admin.getSessions();
    assertEquals(1, sessions.size());
    Session s = sessions.iterator().next();

    assertEquals("user@teiid-security", s.getUserName());
    assertEquals("test", s.getApplicationName());
    assertEquals("bqt", s.getVDBName());
    assertEquals(1, s.getVDBVersion());
    assertNotNull(s.getSessionId());

    conn.close();

    conn =
        TeiidDriver.getInstance()
            .connect(
                "jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user;ApplicationName=test",
                null);
    sessions = admin.getSessions();
    assertEquals(1, sessions.size());
    s = sessions.iterator().next();

    admin.terminateSession(s.getSessionId());
    sessions = admin.getSessions();
    assertEquals(0, sessions.size());
    conn.close();
  }
Ejemplo n.º 23
0
  @Override
  public void deployVdb(IFile vdbFile) throws Exception {
    ArgCheck.isNotNull(vdbFile, "vdbFile"); // $NON-NLS-1$

    String vdbName = vdbFile.getFullPath().lastSegment();
    String vdbNameNoExt = vdbFile.getFullPath().removeFileExtension().lastSegment();

    admin.deployVDB(vdbName, vdbFile.getContents());

    // Refresh VDBs list
    refreshVDBs();

    // TODO should get version from vdbFile
    VDB vdb = admin.getVDB(vdbNameNoExt, 1);

    // If the VDB is still loading, refresh again and potentially start refresh job
    if (!vdb.getStatus().equals(VDB.Status.ACTIVE) && vdb.getValidityErrors().isEmpty()) {
      // Give a 0.5 sec pause for the VDB to finish loading metadata.
      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
      }
      // Refresh again to update vdb states
      refreshVDBs();
      vdb = admin.getVDB(vdbNameNoExt, 1);
      // Determine if still loading, if so start refresh job.  User will get dialog that the
      // vdb is still loading - and try again in a few seconds
      if (!vdb.getStatus().equals(VDB.Status.ACTIVE) && vdb.getValidityErrors().isEmpty()) {
        final Job refreshVDBsJob = new RefreshVDBsJob(vdbNameNoExt);
        refreshVDBsJob.schedule();
      }
    }

    this.eventManager.notifyListeners(
        ExecutionConfigurationEvent.createDeployVDBEvent(vdb.getName()));
  }
Ejemplo n.º 24
0
  /*
   * Deploy all jars in the supplied jarList
   * @param admin the Admin instance
   * @param jarList the colon-separated list of jar path locations
   */
  private void deployJars(Admin admin, String jarList) {
    // Path Entries are colon separated
    String[] jarPathStrs = jarList.split("[:]"); // $NON-NLS-1$

    // Attempt to deploy each jar
    for (String jarPathStr : jarPathStrs) {
      File theFile = new File(jarPathStr);
      if (theFile.exists()) {
        if (theFile.canRead()) {
          String fileName = theFile.getName();
          InputStream iStream = null;
          try {
            iStream = new FileInputStream(theFile);
          } catch (FileNotFoundException ex) {
            LogManager.logError(
                getClass().getSimpleName(),
                ex,
                NLS.bind(Messages.JarDeploymentJarNotFound, theFile.getPath()));
            continue;
          }
          try {
            admin.deployVDB(fileName, iStream);
          } catch (Exception ex) {
            // Jar deployment failed
            LogManager.logError(
                getClass().getSimpleName(),
                ex,
                NLS.bind(Messages.JarDeploymentFailed, theFile.getPath()));
          }
        } else {
          // Could not read the file
          LogManager.logError(
              getClass().getSimpleName(),
              NLS.bind(Messages.JarDeploymentJarNotReadable, theFile.getPath()));
        }
      } else {
        // The file was not found
        LogManager.logError(
            getClass().getSimpleName(),
            NLS.bind(Messages.JarDeploymentJarNotFound, theFile.getPath()));
      }
    }
  }
  @Test
  public void testCreateConnectionFactory() throws Exception {
    String deployedName = "wsOne";

    assertFalse(admin.getDataSourceNames().contains(deployedName));

    Properties p = new Properties();
    p.setProperty("class-name", "org.teiid.resource.adapter.ws.WSManagedConnectionFactory");
    p.setProperty("EndPoint", "{endpoint}");
    admin.createDataSource(deployedName, "webservice", p);

    assertTrue(admin.getDataSourceNames().contains(deployedName));

    admin.deleteDataSource(deployedName);

    assertFalse(admin.getDataSourceNames().contains(deployedName));

    admin.createDataSource(deployedName, "webservice", p);

    assertTrue(admin.getDataSourceNames().contains(deployedName));

    admin.deleteDataSource(deployedName);
  }
 @Test
 public void getWorkerPoolStats() throws Exception {
   deployVdb();
   assertNotNull(admin.getWorkerPoolStats());
 }
Ejemplo n.º 27
0
 @After
 public void teardown() throws AdminException {
   AdminUtil.cleanUp(admin);
   admin.close();
 }
Ejemplo n.º 28
0
 private IStatus pingAdmin() throws Exception {
   admin.getSessions();
   return Status.OK_STATUS;
 }
  @Test
  public void testVDBDeployment() throws Exception {
    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    Collection<String> dsNames = admin.getDataSourceNames();
    if (dsNames.contains("Oracle11_PushDS")) {
      admin.deleteDataSource("Oracle11_PushDS");
    }

    admin.deploy("bqt.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt.vdb")));

    vdbs = admin.getVDBs();
    assertFalse(vdbs.isEmpty());

    VDB vdb = admin.getVDB("bqt", 1);
    assertFalse(vdb.isValid());
    assertTrue(AdminUtil.waitForVDBLoad(admin, "bqt", 1, 3));
    assertFalse(vdb.isValid());

    Properties props = new Properties();
    props.setProperty("connection-url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    props.setProperty("user-name", "sa");
    props.setProperty("password", "sa");
    props.setProperty("connection-properties", "foo=bar,blah=blah");

    admin.createDataSource("Oracle11_PushDS", "h2", props);

    vdb = admin.getVDB("bqt", 1);
    assertTrue(vdb.isValid());
    assertTrue(vdb.getStatus().equals(Status.ACTIVE));

    dsNames = admin.getDataSourceNames();
    assertTrue(dsNames.contains("Oracle11_PushDS"));

    admin.deleteDataSource("Oracle11_PushDS");
    vdb = admin.getVDB("bqt", 1);
    assertFalse(vdb.isValid());
  }