use of org.jvnet.hk2.config.Transaction in project Payara by payara.
the class MonitoredAttributeBagResource method put.
/**
* Creates new monitored-attributes. This method deletes all of the existing
* monitored-attributes.
*
* @param attributes the list of monitored-attributes to be created.
* @return a list of the monitored-attributes after the transaction.
*/
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ActionReportResult put(List<Map<String, String>> attributes) {
RestActionReporter ar = new RestActionReporter();
ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ar.setActionDescription("monitored-attribute");
try {
setMonitoredAttributes(attributes);
List monitoredAttributes = getMonitoredAttributes();
Properties extraProperties = new Properties();
extraProperties.put("monitoredAttributes", monitoredAttributes);
ar.setExtraProperties(extraProperties);
} catch (TransactionFailure ex) {
ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
ar.setMessage(ex.getMessage());
}
return new ActionReportResult(tagName, ar, new OptionsResult(Util.getResourceName(uriInfo)));
}
use of org.jvnet.hk2.config.Transaction in project Payara by payara.
the class ModuleInfo method save.
/**
* Saves its state to the configuration. this method must be called within a transaction
* to the configured module instance.
*
* @param module the module being persisted
*/
public void save(Module module) throws TransactionFailure, PropertyVetoException {
// write out the module properties only for composite app
if (Boolean.valueOf(moduleProps.getProperty(ServerTags.IS_COMPOSITE))) {
moduleProps.remove(ServerTags.IS_COMPOSITE);
for (Iterator itr = moduleProps.keySet().iterator(); itr.hasNext(); ) {
String propName = (String) itr.next();
Property prop = module.createChild(Property.class);
module.getProperty().add(prop);
prop.setName(propName);
prop.setValue(moduleProps.getProperty(propName));
}
}
for (EngineRef ref : _getEngineRefs()) {
Engine engine = module.createChild(Engine.class);
module.getEngines().add(engine);
ref.save(engine);
}
}
use of org.jvnet.hk2.config.Transaction in project Payara by payara.
the class LDAPAdminAccessConfigurator method updateSecurityProvider.
/* private String getNewRealmName(SecurityService ss) {
List<AuthRealm> realms = ss.getAuthRealm();
String pref = ORIG_ADMIN_REALM_NAME + "-";
int index = 0; //last one
for (AuthRealm realm : realms) {
if (realm.getName().indexOf(pref) >= 0) {
index = Integer.parseInt(realm.getName().substring(pref.length()));
}
}
return pref + (index+1);
}*/
private void updateSecurityProvider(final Transaction t, final SecurityProvider w_sp, final StringBuilder sb) throws TransactionFailure, PropertyVetoException {
for (SecurityProviderConfig spc : w_sp.getSecurityProviderConfig()) {
if ((spc instanceof LoginModuleConfig) && spc.getName().equals(ADMIN_FILE_LM_NAME)) {
final LoginModuleConfig w_lmConfig = t.enroll((LoginModuleConfig) spc);
w_lmConfig.setModuleClass(LDAPLoginModule.class.getName());
sb.append(lsm.getString("ldap.authProviderConfigOK", w_sp.getName()));
return;
}
}
throw new TransactionFailure(lsm.getString("ldap.noAuthProviderConfig", w_sp.getName(), ADMIN_FILE_LM_NAME));
}
use of org.jvnet.hk2.config.Transaction in project Payara by payara.
the class CreateApplicationRefCommand method execute.
/**
* Entry point from the framework into the command execution
* @param context context for the command.
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
// retrieve matched version(s) if exist
List<String> matchedVersions = null;
if (enabled) {
try {
// warn users that they can use version expressions
VersioningUtils.checkIdentifier(name);
matchedVersions = new ArrayList<String>(1);
matchedVersions.add(name);
} catch (VersioningWildcardException ex) {
// a version expression is supplied with enabled == true
report.setMessage(localStrings.getLocalString("wildcard.not.allowed", "WARNING : version expression are available only with --enabled=false"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
} catch (VersioningSyntaxException ex) {
report.setMessage(ex.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (!deployment.isRegistered(name)) {
report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", name));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
// retrieve matched version(s) if exist
try {
matchedVersions = versioningService.getMatchedVersions(name, null);
} catch (VersioningException e) {
report.failure(logger, e.getMessage());
return;
}
// this is an unversioned behavior and the given application is not registered
if (matchedVersions.isEmpty()) {
report.setMessage(localStrings.getLocalString("ref.not.referenced.target", "Application {0} is not referenced by target {1}", name, target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ActionReport.MessagePart part = report.getTopMessagePart();
boolean isVersionExpression = VersioningUtils.isVersionExpression(name);
// for each matched version
Iterator it = matchedVersions.iterator();
while (it.hasNext()) {
String appName = (String) it.next();
Application app = applications.getApplication(appName);
ApplicationRef applicationRef = domain.getApplicationRefInTarget(appName, target);
if (applicationRef != null) {
// if a versioned name has been provided to the command
if (isVersionExpression) {
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(localStrings.getLocalString("appref.already.exists", "Application reference {0} already exists in target {1}.", appName, target));
} else {
// returns failure if an untagged name has been provided to the command
report.setMessage(localStrings.getLocalString("appref.already.exists", "Application reference {0} already exists in target {1}.", name, target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
Transaction t = new Transaction();
if (app.isLifecycleModule()) {
handleLifecycleModule(context, t);
return;
}
ReadableArchive archive;
File file = null;
DeployCommandParameters commandParams = null;
Properties contextProps;
Map<String, Properties> modulePropsMap = null;
ApplicationConfigInfo savedAppConfig = null;
try {
commandParams = app.getDeployParameters(null);
commandParams.origin = Origin.create_application_ref;
commandParams.command = Command.create_application_ref;
commandParams.target = target;
commandParams.virtualservers = virtualservers;
commandParams.enabled = enabled;
if (lbenabled != null) {
commandParams.lbenabled = lbenabled;
}
commandParams.type = app.archiveType();
contextProps = app.getDeployProperties();
modulePropsMap = app.getModulePropertiesMap();
savedAppConfig = new ApplicationConfigInfo(app);
URI uri = new URI(app.getLocation());
file = new File(uri);
if (!file.exists()) {
report.setMessage(localStrings.getLocalString("fnf", "File not found", file.getAbsolutePath()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
archive = archiveFactory.openArchive(file);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error opening deployable artifact : " + file.getAbsolutePath(), e);
report.setMessage(localStrings.getLocalString("unknownarchiveformat", "Archive format not recognized"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
final ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, commandParams, report).source(archive).build();
Properties appProps = deploymentContext.getAppProps();
appProps.putAll(contextProps);
// relativize the location so it could be set properly in
// domain.xml
String location = DeploymentUtils.relativizeWithinDomainIfPossible(new URI(app.getLocation()));
appProps.setProperty(ServerTags.LOCATION, location);
// relativize the URI properties so they could store in the
// domain.xml properly on the instances
String appLocation = appProps.getProperty(Application.APP_LOCATION_PROP_NAME);
appProps.setProperty(Application.APP_LOCATION_PROP_NAME, DeploymentUtils.relativizeWithinDomainIfPossible(new URI(appLocation)));
String planLocation = appProps.getProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME);
if (planLocation != null) {
appProps.setProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME, DeploymentUtils.relativizeWithinDomainIfPossible(new URI(planLocation)));
}
String altDDLocation = appProps.getProperty(Application.ALT_DD_LOCATION_PROP_NAME);
if (altDDLocation != null) {
appProps.setProperty(Application.ALT_DD_LOCATION_PROP_NAME, DeploymentUtils.relativizeWithinDomainIfPossible(new URI(altDDLocation)));
}
String runtimeAltDDLocation = appProps.getProperty(Application.RUNTIME_ALT_DD_LOCATION_PROP_NAME);
if (runtimeAltDDLocation != null) {
appProps.setProperty(Application.RUNTIME_ALT_DD_LOCATION_PROP_NAME, DeploymentUtils.relativizeWithinDomainIfPossible(new URI(runtimeAltDDLocation)));
}
savedAppConfig.store(appProps);
if (modulePropsMap != null) {
deploymentContext.setModulePropsMap(modulePropsMap);
}
if (enabled) {
versioningService.handleDisable(appName, target, deploymentContext.getActionReport(), context.getSubject());
}
if (domain.isCurrentInstanceMatchingTarget(target, appName, server.getName(), null)) {
deployment.deploy(deployment.getSniffersFromApp(app), deploymentContext);
} else {
// send the APPLICATION_PREPARED event for DAS
events.send(new Event<DeploymentContext>(Deployment.APPLICATION_PREPARED, deploymentContext), false);
}
final List<String> targets = new ArrayList<String>(Arrays.asList(commandParams.target.split(",")));
List<String> deploymentTarget = new ArrayList<>();
// If targets contains Deployment Group, check if the application is already deployed to instances in it.
for (String target : targets) {
if (isDeploymentGroup(target)) {
List<Server> instances = domain.getDeploymentGroupNamed(target).getInstances();
for (Server instance : instances) {
List<Application> applications = domain.getApplicationsInTarget(instance.getName());
List<String> listOfApplications = new ArrayList<>();
for (Application application : applications) {
listOfApplications.add(application.getName());
}
if (!listOfApplications.contains(appName)) {
deploymentTarget.add(instance.getName());
}
}
}
}
if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
try {
deployment.registerAppInDomainXML(null, deploymentContext, t, true);
} catch (TransactionFailure e) {
logger.warning("failed to create application ref for " + appName);
}
}
// if the target is DAS, we do not need to do anything more
if (!isVersionExpression && DeploymentUtils.isDASTarget(target)) {
return;
}
final ParameterMap paramMap = deployment.prepareInstanceDeployParamMap(deploymentContext);
if (!deploymentTarget.isEmpty()) {
replicateCommand(deploymentTarget, context, paramMap);
} else {
replicateCommand(targets, context, paramMap);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error during creating application ref ", e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
} finally {
try {
archive.close();
} catch (IOException e) {
logger.log(Level.INFO, "Error while closing deployable artifact : " + file.getAbsolutePath(), e);
}
}
}
}
}
use of org.jvnet.hk2.config.Transaction in project Payara by payara.
the class ApplicationLifecycle method prepareAppConfigChanges.
// prepare application config change for later registering
// in the domain.xml
@Override
public Transaction prepareAppConfigChanges(final DeploymentContext context) throws TransactionFailure {
final Properties appProps = context.getAppProps();
final DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
Transaction t = new Transaction();
try {
// prepare the application element
ConfigBean newBean = ((ConfigBean) ConfigBean.unwrap(applications)).allocate(Application.class);
Application app = newBean.createProxy();
Application app_w = t.enroll(app);
setInitialAppAttributes(app_w, deployParams, appProps, context);
context.addTransientAppMetaData(ServerTags.APPLICATION, app_w);
} catch (TransactionFailure e) {
t.rollback();
throw e;
} catch (Exception e) {
t.rollback();
throw new TransactionFailure(e.getMessage(), e);
}
return t;
}
Aggregations