use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.
the class ResteasyEnabler method finishedDeployment.
@Override
public void finishedDeployment(String name, CompositeVDB cvdb) {
final VDBMetaData vdb = cvdb.getVDB();
if (!vdb.getStatus().equals(Status.ACTIVE)) {
return;
}
final String warName = buildName(name, cvdb.getVDB().getVersion());
if (generator.hasRestMetadata(vdb)) {
final Runnable job = new Runnable() {
@Override
public void run() {
try {
byte[] warContents = generator.getContent(vdb);
if (!vdb.getStatus().equals(Status.ACTIVE)) {
return;
}
if (warContents != null) {
// make it a non-persistent deployment
getAdmin().deploy(warName, new ByteArrayInputStream(warContents), false);
}
} catch (IOException e) {
LogManager.logWarning(LogConstants.CTX_RUNTIME, e, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50109, warName));
} catch (AdminException e) {
LogManager.logWarning(LogConstants.CTX_RUNTIME, e, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50109, warName));
}
}
};
getExecutor().execute(job);
}
}
use of org.teiid.adminapi.impl.VDBMetaData 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());
}
}
}
use of org.teiid.adminapi.impl.VDBMetaData 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>());
}
use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.
the class VDBDeployer method undeploy.
@Override
public void undeploy(final DeploymentUnit deploymentUnit) {
if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
return;
}
final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
if (!this.shutdownListener.isShutdownInProgress()) {
final VDBMetaData vdb = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
ServiceController<?> sc = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.OBJECT_SERIALIZER);
if (sc != null) {
ObjectSerializer serilalizer = ObjectSerializer.class.cast(sc.getValue());
serilalizer.removeAttachments(vdb);
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB " + vdb.getName() + " metadata removed");
}
}
this.vdbRepository.removeVDB(deployment.getName(), deployment.getVersion());
ServiceController<?> switchSvc = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion()));
if (switchSvc != null) {
switchSvc.setMode(ServiceController.Mode.REMOVE);
}
for (ModelMetaData model : deployment.getModelMetaDatas().values()) {
for (SourceMappingMetadata smm : model.getSources().values()) {
String dsName = smm.getConnectionJndiName();
if (dsName == null) {
continue;
}
ServiceController<?> dsService;
try {
dsService = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.dsListenerServiceName(deployment.getName(), deployment.getVersion(), dsName));
} catch (InvalidServiceNameException e) {
continue;
}
if (dsService != null) {
dsService.setMode(ServiceController.Mode.REMOVE);
}
}
}
final ServiceController<?> controller = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()));
if (controller != null) {
controller.setMode(ServiceController.Mode.REMOVE);
}
}
use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.
the class VDBParserDeployer method parseVDBDDL.
private VDBMetaData parseVDBDDL(VirtualFile file, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, boolean xmlDeployment) throws DeploymentUnitProcessingException {
try {
PropertyReplacer replacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
String vdbContents = replacer.replaceProperties(ObjectConverterUtil.convertToString(file.openStream()));
ObjectSerializer serializer = ObjectSerializer.class.cast(phaseContext.getServiceRegistry().getService(TeiidServiceNames.OBJECT_SERIALIZER).getValue());
DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(vdbRepo);
VDBMetaData vdb = store.getVDBMetadata(vdbContents);
// if there is persisted one, let that be XML version for now.
if (serializer.buildVdbXml(vdb).exists()) {
vdb = VDBMetadataParser.unmarshell(new FileInputStream(serializer.buildVdbXml(vdb)));
}
vdb.setStatus(Status.LOADING);
vdb.setXmlDeployment(xmlDeployment);
deploymentUnit.putAttachment(TeiidAttachments.VDB_METADATA, vdb);
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_RUNTIME, "VDB " + file.getName() + " has been parsed.");
return vdb;
} catch (XMLStreamException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
}
}
Aggregations