use of org.glassfish.api.ActionReport in project Payara by payara.
the class CreateCustomResource method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
HashMap attrList = new HashMap();
attrList.put("factory-class", factoryClass);
attrList.put("res-type", resType);
attrList.put(ResourceConstants.ENABLED, enabled.toString());
attrList.put(JNDI_NAME, jndiName);
attrList.put(ServerTags.DESCRIPTION, description);
ResourceStatus rs;
try {
rs = customResMgr.create(domain.getResources(), attrList, properties, target);
} catch (Exception e) {
Logger.getLogger(CreateCustomResource.class.getName()).log(Level.SEVERE, "Unable to create custom resource " + jndiName, e);
String def = "Custom resource: {0} could not be created, reason: {1}";
report.setMessage(localStrings.getLocalString("create.custom.resource.fail", def, jndiName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
if (rs.getStatus() == ResourceStatus.FAILURE) {
ec = ActionReport.ExitCode.FAILURE;
if (rs.getMessage() == null) {
report.setMessage(localStrings.getLocalString("create.custom.resource.fail", "Custom resource {0} creation failed", jndiName, ""));
}
if (rs.getException() != null)
report.setFailureCause(rs.getException());
}
if (rs.getMessage() != null) {
report.setMessage(rs.getMessage());
}
report.setActionExitCode(ec);
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class MappingGenerator method generateMapping.
/**
* This method will load mapping classes if there is sun-cmp-mappings.xml,
* otherwise it will call the database generation backend to create
* mapping classes and schema. It also generates *.dbschema and
* sun-cmp-mappings.xml in application dir if it is
* in creating mapping classes mode.
* @param ctx an object containing CLI options for
* the database generation backend
* @param inputFilesPath the directory where sun-cmp-mappings.xml is located
* @param generatedXmlsPath the directory where the generated files are located
* @param classout the directory where the classes are located
* @param ignoreSunDeploymentDescriptors use java2db generation if set to <code>true</code>.
* @return a SchemaElement for mapping classes mapped to
* @throws IOException
* @throws DBException
* @throws ModelException
* @throws Schema2BeansException
* @throws SQLException
* @throws GeneratorException
* @throws ConversionException
*/
public SchemaElement generateMapping(DeploymentContext ctx, String inputFilesPath, String generatedXmlsPath, File classout, boolean ignoreSunDeploymentDescriptors) throws IOException, DBException, ModelException, Schema2BeansException, SQLException, GeneratorException, ConversionException {
SchemaElement schema = null;
if (ctx == null)
isVerifyFlag = true;
File cmpMappingFile = getSunCmpMappingFile(inputFilesPath);
boolean mappedBeans = !ignoreSunDeploymentDescriptors && cmpMappingFile.exists();
ResourceReferenceDescriptor cmpResource = checkOrCreateCMPResource(mappedBeans);
// Remember whether or not this mapping was created by Java2DB.
isJavaToDatabaseFlag = DeploymentHelper.isJavaToDatabase(cmpResource.getSchemaGeneratorProperties());
// We *must* get a vendor name if either the beans are not mapped, or
// they are mapped and the javaToDatabase flag is set.
boolean mustHaveDBVendorName = !mappedBeans || (mappedBeans && isJavaToDatabaseFlag);
// Read deployment settings from the deployment descriptor
// and CLI options.
Results deploymentArguments = getDeploymentArguments(ctx, cmpResource, mustHaveDBVendorName);
dbVendorName = deploymentArguments.getDatabaseVendorName();
if (mappedBeans) {
// If it is from verify, skip deployment arguments check.
if (!isVerifyFlag) {
// Warning for user, if required.
String warning = null;
if (isJavaToDatabaseFlag) {
// as per the mapping.
if (deploymentArguments.hasUniqueTableNames()) {
warning = I18NHelper.getMessage(messages, // NOI18N
"EXC_DisallowJava2DBUniqueTableNames", bundle.getApplication().getRegistrationName(), JDOCodeGeneratorHelper.getModuleName(bundle));
logger.warning(warning);
}
} else if (deploymentArguments.hasJavaToDatabaseArgs()) {
// If beans are already mapped but the user gave any Java2DB
// command line arguments, warn the user that these args
// should not be used when module is already mapped.
warning = I18NHelper.getMessage(messages, // NOI18N
"EXC_DisallowJava2DBCLIOverrides", bundle.getApplication().getRegistrationName(), JDOCodeGeneratorHelper.getModuleName(bundle));
logger.warning(warning);
}
if (warning != null) {
ActionReport subActionReport = ctx.getActionReport().addSubActionsReport();
// Propagte warning to client side so that the deployer can see the warning.
Java2DBProcessorHelper.warnUser(subActionReport, warning);
}
}
// Sun-cmp-mapping.xml exists, use normal MappingClass loading
SunCmpMappings sunCmpMappings = getSunCmpMappings(cmpMappingFile);
// Ensure that there is a dbschema for each element of
// sunCmpMappings.
ensureDBSchemaExistence(cmpResource, sunCmpMappings, inputFilesPath, classout);
// load real mapping model and jdo model in memory
Map mappingClasses = loadMappingClasses(sunCmpMappings, getClassLoader());
// Get schema from one of the mapping classes.
// The mapping class element may be null if there is inconsistency
// in sun-cmp-mappings.xml and ejb-jar.xml. For example,
// the bean has mapping information in sun-cmp-mappings.xml but
// no definition in the ejb-jar.xml.
// So iterate over the mappings until the 1st non-null is found.
MappingClassElement mc = null;
Iterator iter = mappingClasses.values().iterator();
while (iter.hasNext()) {
mc = (MappingClassElement) iter.next();
if (mc != null) {
schema = SchemaElement.forName(mc.getDatabaseRoot());
break;
}
}
if (logger.isLoggable(Logger.FINE)) {
logger.fine(// NOI18N
"Loaded mapped beans for " + cmpResource.getJndiName() + ", isJavaToDatabase=" + // NOI18N
isJavaToDatabaseFlag);
}
} else {
// Generate mapping file and dbschema, since either
// sun-cmp-mappings.xml does not exist (e.g. user didn't yet map)
// or DeploymentContext is null (e.g. running under auspices of AVK).
DatabaseGenerator.Results results = generateMappingClasses(dbVendorName, deploymentArguments.getUseUniqueTableNames(), deploymentArguments.getUserPolicy(), inputFilesPath);
// java2db from verifier should not save anything to disk
if (!isVerifyFlag) {
// save SunCmpMapping to sun-cmp-mappings.xml
// in generated XML dir
writeSunCmpMappingFile(results.getMappingClasses(), getSunCmpMappingFile(generatedXmlsPath));
schema = results.getSchema();
// save schema to dbschema file in generated XML dir
writeSchemaFile(schema, classout);
setJavaToDatabase(cmpResource, true);
}
}
return schema;
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class Java2DBProcessorHelper method init.
/**
* Initializes the rest of the settings
*/
public void init() {
if (deploy) {
// DeployCommandParameters are available only on deploy or deploy
// part of redeploy
DeployCommandParameters cliOverrides = ctx.getCommandParameters(DeployCommandParameters.class);
if (logger.isLoggable(Level.FINE)) {
logger.fine("---> cliOverrides " + cliOverrides);
}
cliCreateTables = cliOverrides.createtables;
cliDropAndCreateTables = cliOverrides.dropandcreatetables;
Application application = ctx.getModuleMetaData(Application.class);
appRegisteredName = application.getRegistrationName();
deploymentContextProps.setProperty(APPLICATION_NAME, appRegisteredName);
} else {
// UndeployCommandParameters are available only on undeploy or undeploy
// part of redeploy. In the latter case, cliOverrides.droptables
// is set from cliOverrides.dropandcreatetables passed to redeploy.
UndeployCommandParameters cliOverrides = ctx.getCommandParameters(UndeployCommandParameters.class);
if (logger.isLoggable(Level.FINE)) {
logger.fine("---> cliOverrides " + cliOverrides);
}
cliDropTables = cliOverrides.droptables;
appRegisteredName = deploymentContextProps.getProperty(APPLICATION_NAME);
}
try {
appGeneratedLocation = ctx.getScratchDir("ejb").getCanonicalPath() + File.separator;
} catch (Exception e) {
throw new RuntimeException(I18NHelper.getMessage(messages, // NOI18N
"Java2DBProcessorHelper.generatedlocation", appRegisteredName), e);
}
appDeployedLocation = ctx.getSource().getURI().getSchemeSpecificPart() + File.separator;
ActionReport report = ctx.getActionReport();
subReport = report.addSubActionsReport();
subReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class MEJBNamingObjectProxy method deployMEJB.
private void deployMEJB() throws IOException {
_logger.info("Loading MEJB app on JNDI look up");
ServerContext serverContext = habitat.getService(ServerContext.class);
File mejbArchive = new File(serverContext.getInstallRoot(), "lib/install/applications/mejb.jar");
DeployCommandParameters deployParams = new DeployCommandParameters(mejbArchive);
String targetName = habitat.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME).getName();
deployParams.target = targetName;
deployParams.name = "mejb";
ActionReport report = habitat.getService(ActionReport.class, "plain");
Deployment deployment = habitat.getService(Deployment.class);
ExtendedDeploymentContext dc = deployment.getBuilder(_logger, deployParams, report).source(mejbArchive).build();
deployment.deploy(dc);
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
throw new RuntimeException("Failed to deploy MEJB app: " + report.getFailureCause());
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class ConnectorApplication method event.
/**
* event listener to listen to </code>resource-adapter undeploy validation</code> and
* to validate the undeployment. Undeployment will fail, if resources are found
* and --cascade is not set.
* @param event Event
*/
public void event(Event event) {
if (Deployment.UNDEPLOYMENT_VALIDATION.equals(event.type())) {
// this is an application undeploy event
DeploymentContext dc = (DeploymentContext) event.hook();
UndeployCommandParameters dcp = dc.getCommandParameters(UndeployCommandParameters.class);
if (dcp.name.equals(moduleName) || // Consider the application with embedded RAR being undeployed
(dcp.name.equals(applicationName) && moduleName.contains(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) && moduleName.startsWith(dcp.name))) {
if (dcp.origin != OpsParams.Origin.deploy) {
if (dcp.origin == OpsParams.Origin.undeploy) {
if (!(dcp._ignoreCascade || dcp.cascade)) {
if (resourcesUtil.filterConnectorResources(resourceManager.getAllResources(), moduleName, true).size() > 0) {
String message = localStrings.getString("con.deployer.resources.exist", moduleName);
_logger.log(Level.WARNING, "resources.of.rar.exist", moduleName);
ActionReport report = dc.getActionReport();
report.setMessage(message);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
}
}
}
}
}
Aggregations