use of org.teiid.adminapi.Translator in project teiid by teiid.
the class TestVDBUtility method buildVDB.
public static VDBMetaData buildVDB() {
VDBMetaData vdb = new VDBMetaData();
// $NON-NLS-1$
vdb.setName("myVDB");
// $NON-NLS-1$
vdb.setDescription("vdb description");
vdb.setConnectionType("NONE");
vdb.setVersion(1);
// $NON-NLS-1$ //$NON-NLS-2$
vdb.addProperty("vdb-property", "vdb-value");
// $NON-NLS-1$ //$NON-NLS-2$
vdb.addProperty("vdb-property2", "vdb-value2");
VDBImportMetadata vdbImport = new VDBImportMetadata();
vdbImport.setName("x");
vdbImport.setVersion("2");
vdb.getVDBImports().add(vdbImport);
ModelMetaData modelOne = new ModelMetaData();
// $NON-NLS-1$
modelOne.setName("model-one");
// $NON-NLS-1$ //$NON-NLS-2$
modelOne.addSourceMapping("s1", "translator", "java:mybinding");
// $NON-NLS-1$
modelOne.setModelType(Model.Type.PHYSICAL);
// $NON-NLS-1$ //$NON-NLS-2$
modelOne.addProperty("model-prop", "model-value");
// $NON-NLS-1$ //$NON-NLS-2$
modelOne.addProperty("model-prop", "model-value-override");
modelOne.setVisible(false);
// $NON-NLS-1$ //$NON-NLS-2$
modelOne.addMessage("ERROR", "There is an error in VDB");
// $NON-NLS-1$ //$NON-NLS-2$
modelOne.addMessage("INFO", "Nothing to see here");
modelOne.setDescription("model description");
modelOne.addSourceMetadata("DDL", "DDL Here");
modelOne.addSourceMetadata("OTHER", "other text");
vdb.addModel(modelOne);
ModelMetaData modelTwo = new ModelMetaData();
// $NON-NLS-1$
modelTwo.setName("model-two");
// $NON-NLS-1$ //$NON-NLS-2$
modelTwo.addSourceMapping("s1", "translator", "java:binding-one");
// $NON-NLS-1$ //$NON-NLS-2$
modelTwo.addSourceMapping("s2", "translator", "java:binding-two");
// $NON-NLS-1$
modelTwo.setModelType(Model.Type.VIRTUAL);
// $NON-NLS-1$ //$NON-NLS-2$
modelTwo.addProperty("model-prop", "model-value");
modelTwo.addSourceMetadata("DDL", "DDL Here");
vdb.addModel(modelTwo);
VDBTranslatorMetaData t1 = new VDBTranslatorMetaData();
t1.setName("oracleOverride");
t1.setType("oracle");
t1.setDescription("hello world");
t1.addProperty("my-property", "my-value");
List<Translator> list = new ArrayList<Translator>();
list.add(t1);
vdb.setOverrideTranslators(list);
DataPolicyMetadata roleOne = new DataPolicyMetadata();
// $NON-NLS-1$
roleOne.setName("roleOne");
// $NON-NLS-1$
roleOne.setDescription("roleOne described");
roleOne.setAllowCreateTemporaryTables(true);
roleOne.setGrantAll(true);
PermissionMetaData perm1 = new PermissionMetaData();
// $NON-NLS-1$
perm1.setResourceName("myTable.T1");
perm1.setAllowRead(true);
roleOne.addPermission(perm1);
PermissionMetaData perm2 = new PermissionMetaData();
// $NON-NLS-1$
perm2.setResourceName("myTable.T2");
perm2.setAllowRead(false);
perm2.setAllowDelete(true);
perm2.setCondition("col1 = user()");
perm2.setConstraint(false);
roleOne.addPermission(perm2);
PermissionMetaData perm3 = new PermissionMetaData();
// $NON-NLS-1$
perm3.setResourceName("javascript");
perm3.setAllowLanguage(true);
roleOne.addPermission(perm3);
PermissionMetaData perm4 = new PermissionMetaData();
// $NON-NLS-1$
perm4.setResourceName("myTable.T2.col1");
perm4.setMask("col2");
perm4.setOrder(1);
roleOne.addPermission(perm4);
// $NON-NLS-1$ //$NON-NLS-2$
roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2"));
vdb.addDataPolicy(roleOne);
EntryMetaData em = new EntryMetaData();
em.setPath("/path-one");
em.setDescription("entry one");
em.addProperty("entryone", "1");
vdb.getEntries().add(em);
EntryMetaData em2 = new EntryMetaData();
em2.setPath("/path-two");
vdb.getEntries().add(em2);
return vdb;
}
use of org.teiid.adminapi.Translator in project teiid by teiid.
the class DatabaseUtil method convert.
public static Database convert(VDBMetaData vdb, MetadataStore metadataStore) {
Database db = new Database(vdb.getName(), vdb.getVersion());
db.setProperties(vdb.getPropertiesMap());
if (vdb.getDescription() != null) {
db.setAnnotation(vdb.getDescription());
}
db.setProperty("connection-type", vdb.getConnectionType().name());
db.getMetadataStore().addDataTypes(metadataStore.getDatatypes());
// override translators
List<Translator> translators = vdb.getOverrideTranslators();
for (Translator t : translators) {
// add the base
if (db.getDataWrapper(t.getType()) == null) {
DataWrapper dw = new DataWrapper(t.getType());
db.addDataWrapper(dw);
}
// add override with properties
if (db.getDataWrapper(t.getName()) == null) {
DataWrapper dw = new DataWrapper(t.getName());
dw.setType(t.getType());
for (final String key : t.getProperties().stringPropertyNames()) {
dw.setProperty(key, t.getPropertyValue(key));
}
if (t.getDescription() != null) {
dw.setAnnotation(t.getDescription());
}
db.addDataWrapper(dw);
}
}
Collection<ModelMetaData> models = vdb.getModelMetaDatas().values();
for (ModelMetaData m : models) {
Schema schema = metadataStore.getSchema(m.getName());
// add servers
if (m.isSource()) {
Collection<SourceMappingMetadata> sources = m.getSourceMappings();
for (SourceMappingMetadata s : sources) {
// add translators, that are not override
if (db.getDataWrapper(s.getTranslatorName()) == null) {
DataWrapper dw = new DataWrapper(s.getTranslatorName());
db.addDataWrapper(dw);
}
// add servers
Server server = new Server(s.getName());
server.setJndiName(s.getConnectionJndiName());
server.setDataWrapper(s.getTranslatorName());
// no need to add duplicate definitions.
if (db.getServer(s.getName()) == null) {
db.addServer(server);
schema.addServer(server);
}
}
}
db.addSchema(schema);
}
for (String key : vdb.getDataPolicyMap().keySet()) {
DataPolicyMetadata dpm = vdb.getDataPolicyMap().get(key);
Role role = new Role(dpm.getName());
if (dpm.getMappedRoleNames() != null && !dpm.getMappedRoleNames().isEmpty()) {
role.setJaasRoles(dpm.getMappedRoleNames());
}
if (dpm.isAnyAuthenticated()) {
role.setAnyAuthenticated(true);
}
Grant grant = null;
if (dpm.isGrantAll()) {
if (grant == null) {
grant = new Grant();
grant.setRole(role.getName());
}
Permission permission = new Permission();
permission.setAllowAllPrivileges(true);
permission.setResourceType(ResourceType.DATABASE);
grant.addPermission(permission);
}
if (dpm.isAllowCreateTemporaryTables() != null && dpm.isAllowCreateTemporaryTables()) {
if (grant == null) {
grant = new Grant();
grant.setRole(role.getName());
}
Permission permission = new Permission();
permission.setAllowTemporyTables(true);
permission.setResourceType(ResourceType.DATABASE);
grant.addPermission(permission);
}
for (DataPolicy.DataPermission dp : dpm.getPermissions()) {
if (grant == null) {
grant = new Grant();
grant.setRole(role.getName());
}
Permission permission = convert(dp);
grant.addPermission(permission);
}
db.addRole(role);
db.addGrant(grant);
}
return db;
}
use of org.teiid.adminapi.Translator in project teiid by teiid.
the class VDBDeployer method deploy.
public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
return;
}
final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
VDBMetaData other = this.vdbRepository.getVDB(deployment.getName(), deployment.getVersion());
if (other != null) {
String deploymentName = other.getPropertyValue(TranslatorUtil.DEPLOYMENT_NAME);
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50106, deployment, deploymentName));
}
deployment.addProperty(TranslatorUtil.DEPLOYMENT_NAME, deploymentUnit.getName());
// check to see if there is old vdb already deployed.
final ServiceController<?> controller = context.getServiceRegistry().getService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()));
if (controller != null) {
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50019, deployment));
controller.setMode(ServiceController.Mode.REMOVE);
}
boolean preview = deployment.isPreview();
if (!preview && deployment.hasErrors()) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50074, deployment));
}
// make sure the translator defined exists in configuration; otherwise add as error
for (ModelMetaData model : deployment.getModelMetaDatas().values()) {
if (!model.isSource() || model.getSourceNames().isEmpty()) {
continue;
}
for (String source : model.getSourceNames()) {
String translatorName = model.getSourceTranslatorName(source);
if (deployment.isOverideTranslator(translatorName)) {
VDBTranslatorMetaData parent = deployment.getTranslator(translatorName);
translatorName = parent.getType();
}
Translator translator = this.translatorRepository.getTranslatorMetaData(translatorName);
if (translator == null) {
String msg = IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50077, translatorName, deployment.getName(), deployment.getVersion());
LogManager.logWarning(LogConstants.CTX_RUNTIME, msg);
}
}
}
// add VDB module's classloader as an attachment
ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
deployment.addAttchment(ClassLoader.class, classLoader);
deployment.addAttchment(ScriptEngineManager.class, new ScriptEngineManager(classLoader));
try {
EmbeddedServer.createPreParser(deployment);
} catch (TeiidException e1) {
throw new DeploymentUnitProcessingException(e1);
}
UDFMetaData udf = deploymentUnit.removeAttachment(TeiidAttachments.UDF_METADATA);
if (udf == null) {
udf = new UDFMetaData();
}
udf.setFunctionClassLoader(classLoader);
deployment.addAttchment(UDFMetaData.class, udf);
VirtualFile file = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
VDBResources resources;
try {
resources = new VDBResources(file, deployment);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
}
this.vdbRepository.addPendingDeployment(deployment);
// build a VDB service
final VDBService vdb = new VDBService(deployment, resources, shutdownListener);
// $NON-NLS-1$
vdb.addMetadataRepository("index", new IndexMetadataRepository());
final ServiceBuilder<RuntimeVDB> vdbService = context.getServiceTarget().addService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()), vdb);
// add dependencies to data-sources
dataSourceDependencies(deployment, context.getServiceTarget());
for (VDBImport vdbImport : deployment.getVDBImports()) {
VDBKey vdbKey = new VDBKey(vdbImport.getName(), vdbImport.getVersion());
if (vdbKey.isAtMost()) {
// TODO: could allow partial versions here if we canonicalize
throw new DeploymentUnitProcessingException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40144, deployment, vdbKey));
}
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50115, deployment, vdbKey));
vdbService.addDependency(TeiidServiceNames.vdbFinishedServiceName(vdbImport.getName(), vdbKey.getVersion()));
}
// adding the translator services is redundant, however if one is removed then it is an issue.
for (Model model : deployment.getModels()) {
List<String> sourceNames = model.getSourceNames();
for (String sourceName : sourceNames) {
String translatorName = model.getSourceTranslatorName(sourceName);
if (deployment.isOverideTranslator(translatorName)) {
VDBTranslatorMetaData translator = deployment.getTranslator(translatorName);
translatorName = translator.getType();
}
vdbService.addDependency(TeiidServiceNames.translatorServiceName(translatorName));
}
}
ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
vdbService.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, vdb.vdbRepositoryInjector);
vdbService.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, vdb.translatorRepositoryInjector);
vdbService.addDependency(TeiidServiceNames.THREAD_POOL_SERVICE, Executor.class, vdb.executorInjector);
vdbService.addDependency(TeiidServiceNames.OBJECT_SERIALIZER, ObjectSerializer.class, vdb.serializerInjector);
vdbService.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, vdb.vdbStatusCheckInjector);
vdbService.addDependency(vdbSwitchServiceName, CountDownLatch.class, new InjectedValue<CountDownLatch>());
// VDB restart switch, control the vdbservice by adding removing the switch service. If you
// remove the service by setting status remove, there is no way start it back up if vdbservice used alone
installVDBSwitchService(context.getServiceTarget(), vdbSwitchServiceName);
vdbService.addListener(new AbstractServiceListener<Object>() {
@Override
public void transition(final ServiceController controller, final ServiceController.Transition transition) {
if (transition.equals(ServiceController.Transition.DOWN_to_WAITING)) {
RuntimeVDB runtimeVDB = RuntimeVDB.class.cast(controller.getValue());
if (runtimeVDB != null && runtimeVDB.isRestartInProgress()) {
ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
ServiceController<?> switchSvc = controller.getServiceContainer().getService(vdbSwitchServiceName);
if (switchSvc != null) {
CountDownLatch latch = CountDownLatch.class.cast(switchSvc.getValue());
try {
latch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// todo:log it?
}
}
installVDBSwitchService(controller.getServiceContainer(), vdbSwitchServiceName);
}
}
}
});
vdbService.setInitialMode(Mode.PASSIVE).install();
}
use of org.teiid.adminapi.Translator in project teiid by teiid.
the class VDBMetadataMapper method wrap.
public ModelNode wrap(VDBMetaData vdb, ModelNode node) {
if (vdb == null) {
return null;
}
node.get(TYPE).set(ModelType.OBJECT);
node.get(VDBNAME).set(vdb.getName());
node.get(CONNECTIONTYPE).set(vdb.getConnectionType().toString());
node.get(STATUS).set(vdb.getStatus().toString());
node.get(VERSION).set(vdb.getVersion());
if (vdb.getDescription() != null) {
node.get(VDB_DESCRIPTION).set(vdb.getDescription());
}
node.get(XML_DEPLOYMENT).set(vdb.isXmlDeployment());
// PROPERTIES
addProperties(node, vdb);
// IMPORT-VDBS
List<VDBImportMetadata> imports = vdb.getVDBImports();
if (imports != null && !imports.isEmpty()) {
ModelNode importNodes = node.get(IMPORT_VDBS);
for (VDBImportMetadata vdbImport : imports) {
importNodes.add(VDBImportMapper.INSTANCE.wrap(vdbImport, new ModelNode()));
}
}
// ENTRIES
List<EntryMetaData> entries = vdb.getEntries();
if (entries != null && !entries.isEmpty()) {
ModelNode entryNodes = node.get(ENTRIES);
for (EntryMetaData entry : entries) {
entryNodes.add(EntryMapper.INSTANCE.wrap(entry, new ModelNode()));
}
}
// MODELS
Map<String, ModelMetaData> models = vdb.getModelMetaDatas();
if (models != null && !models.isEmpty()) {
ModelNode modelNodes = node.get(MODELS);
for (ModelMetaData model : models.values()) {
modelNodes.add(ModelMetadataMapper.INSTANCE.wrap(model, new ModelNode()));
}
}
// OVERRIDE_TRANSLATORS
List<Translator> translators = vdb.getOverrideTranslators();
if (translators != null && !translators.isEmpty()) {
ModelNode translatorNodes = node.get(OVERRIDE_TRANSLATORS);
for (Translator translator : translators) {
translatorNodes.add(VDBTranslatorMetaDataMapper.INSTANCE.wrap((VDBTranslatorMetaData) translator, new ModelNode()));
}
}
// DATA_POLICIES
List<DataPolicy> policies = vdb.getDataPolicies();
if (policies != null && !policies.isEmpty()) {
ModelNode dataPoliciesNodes = node.get(DATA_POLICIES);
for (DataPolicy policy : policies) {
dataPoliciesNodes.add(DataPolicyMetadataMapper.INSTANCE.wrap((DataPolicyMetadata) policy, new ModelNode()));
}
}
wrapDomain(vdb, node);
return node;
}
use of org.teiid.adminapi.Translator in project teiid by teiid.
the class VDBService method start.
@Override
public void start(final StartContext context) throws StartException {
ConnectorManagerRepository cmr = new ConnectorManagerRepository();
TranslatorRepository repo = new TranslatorRepository();
this.vdb.addAttchment(TranslatorRepository.class, repo);
// check if this is a VDB with index files, if there are then build the TransformationMetadata
UDFMetaData udf = this.vdb.getAttachment(UDFMetaData.class);
// add required connector managers; if they are not already there
for (Translator t : this.vdb.getOverrideTranslators()) {
VDBTranslatorMetaData data = (VDBTranslatorMetaData) t;
String type = data.getType();
VDBTranslatorMetaData parent = getTranslatorRepository().getTranslatorMetaData(type);
data.setModuleName(parent.getModuleName());
data.addAttchment(ClassLoader.class, parent.getAttachment(ClassLoader.class));
data.setParent(parent);
repo.addTranslatorMetadata(data.getName(), data);
}
createConnectorManagers(cmr, repo, this.vdb);
final ServiceBuilder<Void> vdbService = addVDBFinishedService(context);
this.vdbListener = new VDBLifeCycleListener() {
@Override
public void added(String name, CompositeVDB cvdb) {
}
@Override
public void beforeRemove(String name, CompositeVDB cvdb) {
}
@Override
public void removed(String name, CompositeVDB cvdb) {
}
@Override
public void finishedDeployment(String name, CompositeVDB cvdb) {
if (!VDBService.this.vdbKey.equals(cvdb.getVDBKey())) {
return;
}
// clear out the indexmetadatarepository as it holds state that is no longer necessary
// $NON-NLS-1$
repositories.put("index", new IndexMetadataRepository());
VDBMetaData vdbInstance = cvdb.getVDB();
if (vdbInstance.getStatus().equals(Status.ACTIVE)) {
vdbService.install();
}
}
};
getVDBRepository().addListener(this.vdbListener);
MetadataStore store = new MetadataStore();
try {
// check to see if there is an index file. if there is then we assume
// that index is the default metadata repo
MetadataRepository<?, ?> defaultRepo = null;
for (String s : this.vdbResources.getEntriesPlusVisibilities().keySet()) {
if (s.endsWith(VDBResources.INDEX_EXT)) {
// $NON-NLS-1$
defaultRepo = super.getMetadataRepository("index");
break;
}
}
this.assignMetadataRepositories(vdb, defaultRepo);
// add transformation metadata to the repository.
getVDBRepository().addVDB(this.vdb, store, vdbResources.getEntriesPlusVisibilities(), udf, cmr);
} catch (VirtualDatabaseException e) {
cleanup(context);
throw new StartException(e);
}
this.vdb.removeAttachment(UDFMetaData.class);
try {
loadMetadata(this.vdb, cmr, store, this.vdbResources);
} catch (TranslatorException e) {
cleanup(context);
throw new StartException(e);
}
this.runtimeVDB = buildRuntimeVDB(this.vdb, context.getController().getServiceContainer());
}
Aggregations