use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.
the class JPADeployer method createEMFs.
/**
* CreateEMFs and save them in persistence
* @param context
*/
private void createEMFs(DeploymentContext context) {
Application application = context.getModuleMetaData(Application.class);
Set<BundleDescriptor> bundles = application.getBundleDescriptors();
// Iterate through all the bundles for the app and collect pu references in referencedPus
boolean hasScopedResource = false;
final List<PersistenceUnitDescriptor> referencedPus = new ArrayList<PersistenceUnitDescriptor>();
for (BundleDescriptor bundle : bundles) {
Collection<? extends PersistenceUnitDescriptor> pusReferencedFromBundle = bundle.findReferencedPUs();
for (PersistenceUnitDescriptor pud : pusReferencedFromBundle) {
referencedPus.add(pud);
if (hasScopedResource(pud)) {
hasScopedResource = true;
}
}
}
if (hasScopedResource) {
// Scoped resources are registered by connector runtime after prepare(). That is too late for JPA
// This is a hack to initialize connectorRuntime for scoped resources
connectorRuntime.registerDataSourceDefinitions(application);
}
// Iterate through all the PUDs for this bundle and if it is referenced, load the corresponding pu
PersistenceUnitDescriptorIterator pudIterator = new PersistenceUnitDescriptorIterator() {
@Override
void visitPUD(PersistenceUnitDescriptor pud, DeploymentContext context) {
if (referencedPus.contains(pud)) {
boolean isDas = isDas();
if (isDas && !isTargetDas(context.getCommandParameters(DeployCommandParameters.class))) {
DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
// If on DAS and not generating schema for remotes then return here
String jpaScemaGeneration = pud.getProperties().getProperty("javax.persistence.schema-generation.database.action", "none").toLowerCase();
String eclipselinkSchemaGeneration = pud.getProperties().getProperty("eclipselink.ddl-generation", "none").toLowerCase();
if ("none".equals(jpaScemaGeneration) && "none".equals(eclipselinkSchemaGeneration)) {
return;
} else {
InternalSystemAdministrator kernelIdentity = Globals.getDefaultHabitat().getService(InternalSystemAdministrator.class);
CommandRunner commandRunner = Globals.getDefaultHabitat().getService(CommandRunner.class);
CommandRunner.CommandInvocation getTranslatedValueCommand = commandRunner.getCommandInvocation("_get-translated-config-value", new PlainTextActionReporter(), kernelIdentity.getSubject());
ParameterMap params = new ParameterMap();
params.add("propertyName", pud.getJtaDataSource());
params.add("target", deployParams.target);
getTranslatedValueCommand.parameters(params);
getTranslatedValueCommand.execute();
ActionReport report = getTranslatedValueCommand.report();
if (report.hasSuccesses() && report.getSubActionsReport().size() == 1) {
ActionReport subReport = report.getSubActionsReport().get(0);
String value = subReport.getMessage().replace(deployParams.target + ":", "");
pud.setJtaDataSource(value.trim());
} else {
logger.log(Level.SEVERE, report.getMessage(), report.getFailureCause());
}
}
}
// While running in embedded mode, it is not possible to guarantee that entity classes are not loaded by the app classloader before transformers are installed
// If that happens, weaving will not take place and EclipseLink will throw up. Provide users an option to disable weaving by passing the flag.
// Note that we enable weaving if not explicitly disabled by user
boolean weavingEnabled = Boolean.valueOf(sc.getArguments().getProperty("org.glassfish.persistence.embedded.weaving.enabled", "true"));
ProviderContainerContractInfo providerContainerContractInfo = weavingEnabled ? new ServerProviderContainerContractInfo(context, connectorRuntime, isDas) : new EmbeddedProviderContainerContractInfo(context, connectorRuntime, isDas);
try {
((ExtendedDeploymentContext) context).prepareScratchDirs();
} catch (IOException e) {
// There is no way to recover if we are not able to create the scratch dirs. Just rethrow the exception.
throw new RuntimeException(e);
}
try {
PersistenceUnitLoader puLoader = new PersistenceUnitLoader(pud, providerContainerContractInfo);
// Store the puLoader in context. It is retrieved to execute java2db and to
// store the loaded emfs in a JPAApplicationContainer object for cleanup
context.addTransientAppMetaData(getUniquePuIdentifier(pud), puLoader);
} catch (Exception e) {
DeployCommandParameters dcp = context.getCommandParameters(DeployCommandParameters.class);
if (dcp.isSkipDSFailure() && ExceptionUtil.isDSFailure(e)) {
logger.log(Level.WARNING, "Resource communication failure exception skipped while loading the pu " + pud.getName(), e);
} else {
if (e.getCause() instanceof ConnectorRuntimeException) {
logger.log(Level.SEVERE, "{0} is not a valid data source. If you are using variable replacement then" + "ensure that is available on the DAS.");
}
throw e;
}
}
}
}
};
pudIterator.iteratePUDs(context);
}
use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.
the class AdminObjectManager method isValidAdminObject.
// TODO Error checking taken from v2, need to refactor for v3
private ResourceStatus isValidAdminObject() {
// Check if the restype is valid -
// To check this, we need to get the list of admin-object-interface
// names and then find out if this list contains the restype.
// boolean isValidAdminObject = true;
boolean isValidAdminObject = false;
// be using that resType
if (className == null) {
String[] resTypes;
try {
resTypes = connectorRuntime.getAdminObjectInterfaceNames(raName);
} catch (ConnectorRuntimeException cre) {
Logger.getLogger(AdminObjectManager.class.getName()).log(Level.SEVERE, "Could not find admin-ojbect-interface names (resTypes) from ConnectorRuntime for resource adapter.", cre);
String msg = localStrings.getLocalString("admin.mbeans.rmb.null_ao_intf", "Resource Adapter {0} does not contain any resource type for admin-object. Please specify another res-adapter.", raName) + " " + cre.getLocalizedMessage();
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
if (resTypes == null || resTypes.length <= 0) {
String msg = localStrings.getLocalString("admin.mbeans.rmb.null_ao_intf", "Resource Adapter {0} does not contain any resource type for admin-object. Please specify another res-adapter.", raName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
int count = 0;
for (int i = 0; i < resTypes.length; i++) {
if (resTypes[i].equals(resType)) {
isValidAdminObject = true;
count++;
}
}
if (count > 1) {
String msg = localStrings.getLocalString("admin.mbeans.rmb.multiple_admin_objects.found.for.restype", "Need to specify admin-object classname parameter (--classname) as multiple admin objects " + "use this resType [ {0} ]", resType);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} else {
try {
isValidAdminObject = connectorRuntime.hasAdminObject(raName, resType, className);
} catch (ConnectorRuntimeException cre) {
Logger.getLogger(AdminObjectManager.class.getName()).log(Level.SEVERE, "Could not find admin-object-interface names (resTypes) and admin-object-classnames from " + "ConnectorRuntime for resource adapter.", cre);
String msg = localStrings.getLocalString("admin.mbeans.rmb.ao_intf_impl_check_failed", "Could not determine admin object resource information of Resource Adapter [ {0} ] for" + "resType [ {1} ] and classname [ {2} ] ", raName, resType, className) + " " + cre.getLocalizedMessage();
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
}
if (!isValidAdminObject) {
String msg = localStrings.getLocalString("admin.mbeans.rmb.invalid_res_type", "Invalid Resource Type: {0}", resType);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
return new ResourceStatus(ResourceStatus.SUCCESS, "");
}
use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.
the class ConnectorMessageBeanClient method setup.
/**
* Gets executed as part of message bean deployment. Creates the
* <code>ActivationSpec</code> javabean and does endpointfactory
* activation with the resource adapter. This code also converts
* all J2EE 1.3 MDB properties to MQ resource adapter activation
* spec properties, if user doesnt specifies resource adapter
* module name in sun-ejb-jar.xml of the MDB. This is done using
* <code>com.sun.enterprise.connector.system.ActiveJmsResourceAdapter
* </code>
*
* @param messageBeanPM <code>MessageBeanProtocolManager</code> object.
*/
public void setup(MessageBeanProtocolManager messageBeanPM) throws Exception {
ClassLoader loader = descriptor_.getEjbBundleDescriptor().getClassLoader();
if (loader == null) {
loader = Thread.currentThread().getContextClassLoader();
}
beanClass_ = loader.loadClass(descriptor_.getEjbClassName());
messageBeanPM_ = messageBeanPM;
String resourceAdapterMid = getResourceAdapterMid(descriptor_);
ActiveInboundResourceAdapter aira = getActiveResourceAdapter(resourceAdapterMid);
aira.updateMDBRuntimeInfo(descriptor_, messageBeanPM_.getPoolDescriptor());
// the resource adapter this MDB client is deployed to
ResourceAdapter ra = aira.getResourceAdapter();
if (ra == null) {
String i18nMsg = localStrings.getString("msg-bean-client.ra.class.not.specified", resourceAdapterMid);
throw new ConnectorRuntimeException(i18nMsg);
}
ConnectorDescriptor desc = aira.getDescriptor();
MessageListener msgListener = getMessageListener(desc);
String activationSpecClassName = null;
if (msgListener != null) {
activationSpecClassName = msgListener.getActivationSpecClass();
}
if (activationSpecClassName != null) {
if (logger.isLoggable(Level.FINEST)) {
String msg = "ActivationSpecClassName = " + activationSpecClassName;
logger.log(Level.FINEST, msg);
}
try {
ActivationSpec activationSpec = getActivationSpec(aira, activationSpecClassName);
activationSpec.setResourceAdapter(ra);
// at this stage, activation-spec is created, config properties merged with ejb-descriptor.
// validate activation-spec now
ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
runtime.getConnectorBeanValidator().validateJavaBean(activationSpec, resourceAdapterMid);
aira.validateActivationSpec(activationSpec);
myState = BLOCKED;
ra.endpointActivation(this, activationSpec);
aira.addEndpointFactoryInfo(beanID_, new MessageEndpointFactoryInfo(this, activationSpec));
} catch (Exception ex) {
Object[] args = new Object[] { resourceAdapterMid, activationSpecClassName, ex };
logger.log(Level.WARNING, "endpoint.activation.failure", args);
throw (Exception) (new Exception()).initCause(ex);
}
} else {
// FIXME throw some exception here.
throw new Exception("Unsupported message listener type");
}
}
use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.
the class ConnectorMessageBeanClient method close.
/**
* Does endpoint deactivation with the resource adapter.
* Also remove sthe <code>MessageEndpointFactoryInfo</code>
* from house keeping.
*/
public void close() {
logger.logp(Level.FINEST, "ConnectorMessageBeanClient", "close", "called...");
// no longer available
started_ = false;
String resourceAdapterMid = null;
try {
resourceAdapterMid = getResourceAdapterMid(descriptor_);
} catch (ConnectorRuntimeException e) {
String message = localStrings.getString("msg-bean-client.could-not-derive-ra-mid", descriptor_.getName());
logger.log(Level.WARNING, message, e);
}
ActiveResourceAdapter activeRar = registry_.getActiveResourceAdapter(resourceAdapterMid);
if (activeRar instanceof ActiveInboundResourceAdapter) {
// in case the RA is already undeployed
ActiveInboundResourceAdapter rar = (ActiveInboundResourceAdapter) activeRar;
MessageEndpointFactoryInfo info = rar.getEndpointFactoryInfo(beanID_);
if (info != null) {
rar.getResourceAdapter().endpointDeactivation(info.getEndpointFactory(), info.getActivationSpec());
rar.removeEndpointFactoryInfo(beanID_);
} else {
logger.log(Level.FINE, "Not de-activating the end point, since it is not activated");
}
}
}
use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.
the class ActiveOutboundResourceAdapter method init.
/**
* Creates an active inbound resource adapter. Sets all RA java bean
* properties and issues a start.
*
* @param ra <code>ResourceAdapter<code> java bean.
* @param desc <code>ConnectorDescriptor</code> object.
* @param moduleName Resource adapter module name.
* @param jcl <code>ClassLoader</code> instance.
* @throws ConnectorRuntimeException If there is a failure in loading
* or starting the resource adapter.
*/
public void init(ResourceAdapter ra, ConnectorDescriptor desc, String moduleName, ClassLoader jcl) throws ConnectorRuntimeException {
super.init(ra, desc, moduleName, jcl);
this.resourceadapter_ = ra;
if (resourceadapter_ != null) {
try {
loadRAConfiguration();
// now the RA bean would have been fully configured (taking into account, resource-adapter-config),
// validate the RA bean now.
beanValidator.validateJavaBean(ra, moduleName);
ConnectorRegistry registry = ConnectorRegistry.getInstance();
String poolId = null;
ResourceAdapterConfig raConfig = registry.getResourceAdapterConfig(moduleName_);
if (raConfig != null) {
poolId = raConfig.getThreadPoolIds();
}
this.bootStrapContextImpl = new BootstrapContextImpl(poolId, moduleName_, jcl);
validateWorkContextSupport(desc);
startResourceAdapter(bootStrapContextImpl);
} catch (ResourceAdapterInternalException ex) {
_logger.log(Level.SEVERE, "rardeployment.start_failed", ex);
String i18nMsg = localStrings.getString("rardeployment.start_failed", ex.getMessage());
ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
cre.initCause(ex);
throw cre;
} catch (Throwable t) {
_logger.log(Level.SEVERE, "rardeployment.start_failed", t);
String i18nMsg = localStrings.getString("rardeployment.start_failed", t.getMessage());
ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
if (t.getCause() != null) {
cre.initCause(t.getCause());
} else {
cre.initCause(t);
}
throw cre;
}
}
}
Aggregations