use of org.teiid.core.TeiidException 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.core.TeiidException in project teiid by teiid.
the class TestValidator method helpRunValidator.
public static ValidatorReport helpRunValidator(Command command, String[] expectedStringArray, QueryMetadataInterface metadata) {
try {
ValidatorReport report = Validator.validate(command, metadata);
examineReport(command, expectedStringArray, report);
return report;
} catch (TeiidException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class SocketProfile method connect.
/**
* This method tries to make a connection to the given URL. This class
* will return a null if this is not the right driver to connect to the given URL.
* @param The URL used to establish a connection.
* @return Connection object created
* @throws SQLException if it is unable to establish a connection to the server.
*/
public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
int loginTimeoutSeconds = 0;
SocketServerConnection serverConn;
try {
String timeout = info.getProperty(TeiidURL.CONNECTION.LOGIN_TIMEOUT);
if (timeout != null) {
loginTimeoutSeconds = Integer.parseInt(timeout);
}
if (loginTimeoutSeconds > 0) {
OioOjbectChannelFactory.TIMEOUTS.set(System.currentTimeMillis() + loginTimeoutSeconds * 1000);
}
serverConn = SocketServerConnectionFactory.getInstance().getConnection(info);
} catch (TeiidException e) {
throw TeiidSQLException.create(e);
} finally {
if (loginTimeoutSeconds > 0) {
OioOjbectChannelFactory.TIMEOUTS.set(null);
}
}
// construct a MMConnection object.
ConnectionImpl connection = new ConnectionImpl(serverConn, info, url);
return connection;
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class ExceptionHolder method writeExternal.
@Override
public void writeExternal(ObjectOutput out) throws IOException {
List<String> classNames = new ArrayList<String>();
Class<?> clazz = exception.getClass();
while (clazz != null) {
if (clazz == Throwable.class || clazz == Exception.class) {
break;
}
classNames.add(clazz.getName());
clazz = clazz.getSuperclass();
}
ExternalizeUtil.writeList(out, classNames);
out.writeObject(exception.getMessage());
out.writeObject(exception.getStackTrace());
if (exception instanceof TeiidException) {
out.writeObject(((TeiidException) exception).getCode());
} else {
out.writeObject(null);
}
// specify that this cause is nested exception; not top level
if (this.exception.getCause() != null && this.exception.getCause() != this.exception) {
out.writeObject(new ExceptionHolder(this.exception.getCause(), true));
} else {
out.writeObject(null);
}
// only for the top level exception write the serialized block for the object
if (!nested) {
out.writeObject(writeAsByteArray(this.exception));
} else {
out.writeObject(null);
}
// handle SQLException chains
if (exception instanceof SQLException) {
if (nested) {
out.writeInt(0);
} else {
SQLException se = (SQLException) exception;
SQLException next = se.getNextException();
int count = 0;
while (next != null) {
count++;
next = next.getNextException();
}
out.writeInt(count);
next = se.getNextException();
while (next != null) {
out.writeObject(new ExceptionHolder(next, true));
next = next.getNextException();
}
}
} else if (exception instanceof SourceWarning) {
SourceWarning sw = (SourceWarning) exception;
out.writeUTF(sw.getConnectorBindingName());
out.writeUTF(sw.getModelName());
out.writeBoolean(sw.isPartialResultsError());
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class ExceptionHolder method buildException.
private Throwable buildException(List<String> classNames, String message, StackTraceElement[] stackTrace, String code) {
String originalClass = Exception.class.getName();
if (!classNames.isEmpty()) {
originalClass = classNames.get(0);
}
// $NON-NLS-1$
List<String> args = Arrays.asList(CorePlugin.Util.getString("ExceptionHolder.converted_exception", message, originalClass));
Throwable result = null;
for (String className : classNames) {
try {
result = (Throwable) ReflectionHelper.create(className, args, ExceptionHolder.class.getClassLoader());
break;
} catch (TeiidException e1) {
//
}
}
if (result == null) {
result = new TeiidRuntimeException(args.get(0));
} else if (result instanceof TeiidException) {
((TeiidException) result).setCode(code);
((TeiidException) result).setOriginalType(classNames.get(0));
}
result.setStackTrace(stackTrace);
return result;
}
Aggregations