Search in sources :

Example 16 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class EngineStatistics method executeOperation.

@Override
protected void executeOperation(OperationContext context, TranslatorRepository repo, ModelNode operation) throws OperationFailedException {
    ModelNode result = context.getResult();
    List<VDBTranslatorMetaData> translators = repo.getTranslators();
    for (VDBTranslatorMetaData t : translators) {
        VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.wrap(t, result.add());
    }
}
Also used : ModelNode(org.jboss.dmr.ModelNode) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 17 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TestAdminObjectBuilder method testTranslator.

@Test
public void testTranslator() {
    VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
    tm.setExecutionFactoryClass(ExecutionFactory.class);
    tm.setName("Oracle");
    tm.addProperty("ExtensionTranslationClassName", "org.teiid.translator.jdbc.oracle.OracleSQLTranslator");
    // convert to managed object and build the VDB out of MO
    ModelNode node = VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.wrap(tm, new ModelNode());
    VDBTranslatorMetaData tm1 = VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.unwrap(node);
    assertEquals("Oracle", tm1.getName());
    assertEquals(ExecutionFactory.class.getName(), tm1.getPropertyValue(Translator.EXECUTION_FACTORY_CLASS));
    assertEquals("org.teiid.translator.jdbc.oracle.OracleSQLTranslator", tm1.getPropertyValue("ExtensionTranslationClassName"));
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) ModelNode(org.jboss.dmr.ModelNode) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) Test(org.junit.Test)

Example 18 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TestAdminObjectBuilder method testVDB.

@Test
public void testVDB() {
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("myVDB");
    vdb.setDescription("vdb description");
    vdb.setVersion(1);
    vdb.addProperty("vdb-property", "vdb-value");
    ModelMetaData modelOne = new ModelMetaData();
    modelOne.setName("model-one");
    modelOne.addSourceMapping("s1", "translator", "java:mybinding");
    modelOne.setModelType(Model.Type.PHYSICAL);
    modelOne.addProperty("model-prop", "model-value");
    modelOne.addProperty("model-prop", "model-value-override");
    modelOne.setVisible(false);
    modelOne.addMessage("ERROR", "There is an error in VDB");
    modelOne.setDescription("model description");
    vdb.addModel(modelOne);
    ModelMetaData modelTwo = new ModelMetaData();
    modelTwo.setName("model-two");
    modelTwo.addSourceMapping("s1", "translator", "java:binding-one");
    modelTwo.addSourceMapping("s2", "translator", "java:binding-two");
    modelTwo.setModelType(Model.Type.VIRTUAL);
    modelTwo.addProperty("model-prop", "model-value");
    vdb.addModel(modelTwo);
    VDBTranslatorMetaData t1 = new VDBTranslatorMetaData();
    t1.setName("oracleOverride");
    t1.setType("oracle");
    t1.addProperty("my-property", "my-value");
    List<Translator> list = new ArrayList<Translator>();
    list.add(t1);
    vdb.setOverrideTranslators(list);
    DataPolicyMetadata roleOne = new DataPolicyMetadata();
    roleOne.setName("roleOne");
    roleOne.setDescription("roleOne described");
    PermissionMetaData perm1 = new PermissionMetaData();
    perm1.setResourceName("myTable.T1");
    perm1.setAllowRead(true);
    roleOne.addPermission(perm1);
    PermissionMetaData perm2 = new PermissionMetaData();
    perm2.setResourceName("myTable.T2");
    perm2.setAllowRead(false);
    perm2.setAllowDelete(true);
    roleOne.addPermission(perm2);
    roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2"));
    vdb.addDataPolicy(roleOne);
    // convert to managed object and build the VDB out of MO
    ModelNode node = VDBMetadataMapper.INSTANCE.wrap(vdb, new ModelNode());
    vdb = VDBMetadataMapper.INSTANCE.unwrap(node);
    assertEquals("myVDB", vdb.getName());
    assertEquals("vdb description", vdb.getDescription());
    assertEquals("1", vdb.getVersion());
    assertEquals("vdb-value", vdb.getPropertyValue("vdb-property"));
    assertNotNull(vdb.getModel("model-one"));
    assertNotNull(vdb.getModel("model-two"));
    assertNull(vdb.getModel("model-unknown"));
    modelOne = vdb.getModel("model-one");
    assertEquals("model-one", modelOne.getName());
    assertEquals("s1", modelOne.getSourceNames().get(0));
    assertEquals(Model.Type.PHYSICAL, modelOne.getModelType());
    assertEquals("model-value-override", modelOne.getPropertyValue("model-prop"));
    assertFalse(modelOne.isVisible());
    assertEquals("model description", modelOne.getDescription());
    modelTwo = vdb.getModel("model-two");
    assertEquals("model-two", modelTwo.getName());
    assertTrue(modelTwo.getSourceNames().contains("s1"));
    assertTrue(modelTwo.getSourceNames().contains("s2"));
    // this is not persisted in the XML
    assertEquals(Model.Type.VIRTUAL, modelTwo.getModelType());
    assertEquals("model-value", modelTwo.getPropertyValue("model-prop"));
    assertTrue(vdb.getValidityErrors().contains("There is an error in VDB"));
    List<Translator> translators = vdb.getOverrideTranslators();
    assertTrue(translators.size() == 1);
    Translator translator = translators.get(0);
    assertEquals("oracleOverride", translator.getName());
    assertEquals("oracle", translator.getType());
    assertEquals("my-value", translator.getPropertyValue("my-property"));
    List<DataPolicy> roles = vdb.getDataPolicies();
    assertTrue(roles.size() == 1);
    DataPolicyMetadata role = vdb.getDataPolicyMap().get("roleOne");
    assertEquals("roleOne described", role.getDescription());
    assertNotNull(role.getMappedRoleNames());
    assertTrue(role.getMappedRoleNames().contains("ROLE1"));
    assertTrue(role.getMappedRoleNames().contains("ROLE2"));
    List<DataPolicy.DataPermission> permissions = role.getPermissions();
    assertEquals(2, permissions.size());
    for (DataPolicy.DataPermission p : permissions) {
        if (p.getResourceName().equalsIgnoreCase("myTable.T1")) {
            assertTrue(p.getAllowRead());
            assertNull(p.getAllowDelete());
        } else {
            assertFalse(p.getAllowRead());
            assertTrue(p.getAllowDelete());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Translator(org.teiid.adminapi.Translator) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) DataPolicy(org.teiid.adminapi.DataPolicy) ModelNode(org.jboss.dmr.ModelNode) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 19 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TestVDBService method testMissingDelegate.

@Test(expected = ConnectorManagerException.class)
public void testMissingDelegate() throws ConnectorManagerException {
    TranslatorRepository repo = new TranslatorRepository();
    VDBTranslatorMetaData tmd = new VDBTranslatorMetaData();
    Properties props = new Properties();
    props.put("delegateName", "y");
    tmd.setProperties(props);
    tmd.setExecutionFactoryClass(SampleExecutionFactory.class);
    repo.addTranslatorMetadata("x", tmd);
    TranslatorUtil.getExecutionFactory("x", repo, repo, new VDBMetaData(), new IdentityHashMap<Translator, ExecutionFactory<Object, Object>>(), new HashSet<String>());
}
Also used : TranslatorRepository(org.teiid.dqp.internal.datamgr.TranslatorRepository) Translator(org.teiid.adminapi.Translator) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) BaseDelegatingExecutionFactory(org.teiid.translator.BaseDelegatingExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) Properties(java.util.Properties) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) Test(org.junit.Test)

Example 20 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TranslatorDeployer method undeploy.

@Override
public void undeploy(final DeploymentUnit context) {
    if (!TeiidAttachments.isTranslator(context)) {
        return;
    }
    VDBTranslatorMetaData metadata = context.getAttachment(TeiidAttachments.TRANSLATOR_METADATA);
    if (metadata == null) {
        return;
    }
    final ServiceRegistry registry = context.getServiceRegistry();
    final ServiceName serviceName = TeiidServiceNames.translatorServiceName(metadata.getName());
    final ServiceController<?> controller = registry.getService(serviceName);
    if (controller != null) {
        controller.setMode(Mode.REMOVE);
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Aggregations

VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)27 Test (org.junit.Test)13 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)6 ExecutionFactory (org.teiid.translator.ExecutionFactory)6 ModelNode (org.jboss.dmr.ModelNode)4 Translator (org.teiid.adminapi.Translator)4 ArrayList (java.util.ArrayList)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)3 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)3 TranslatorException (org.teiid.translator.TranslatorException)3 Properties (java.util.Properties)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 Module (org.jboss.modules.Module)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 TeiidException (org.teiid.core.TeiidException)2 UDFMetaData (org.teiid.deployers.UDFMetaData)2 TeiidConstants.asString (org.teiid.jboss.TeiidConstants.asString)2 IndexMetadataRepository (org.teiid.metadata.index.IndexMetadataRepository)2