use of org.jvnet.hk2.config.RetryableException in project Payara by payara.
the class CreateHTTPLoadBalancerCommand method addLoadBalancer.
private void addLoadBalancer(final String lbConfigName) {
LoadBalancers loadBalancers = domain.getExtensionByType(LoadBalancers.class);
// create load-balancers parent element if it does not exist
if (loadBalancers == null) {
Transaction transaction = new Transaction();
try {
ConfigBeanProxy domainProxy = transaction.enroll(domain);
loadBalancers = domainProxy.createChild(LoadBalancers.class);
((Domain) domainProxy).getExtensions().add(loadBalancers);
transaction.commit();
} catch (TransactionFailure ex) {
transaction.rollback();
String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
} catch (RetryableException ex) {
transaction.rollback();
String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
try {
ConfigSupport.apply(new SingleConfigCode<LoadBalancers>() {
@Override
public Object run(LoadBalancers param) throws PropertyVetoException, TransactionFailure {
LoadBalancer lb = param.createChild(LoadBalancer.class);
lb.setDeviceHost(devicehost);
lb.setDevicePort(deviceport);
lb.setLbConfigName(lbConfigName);
lb.setName(load_balancer_name);
// add properties
if (properties != null) {
for (Object propname : properties.keySet()) {
Property newprop = lb.createChild(Property.class);
newprop.setName((String) propname);
newprop.setValue(properties.getProperty((String) propname));
lb.getProperty().add(newprop);
}
}
if (sslproxyhost != null) {
Property newprop = lb.createChild(Property.class);
newprop.setName("ssl-proxy-host");
newprop.setValue(sslproxyhost);
lb.getProperty().add(newprop);
}
if (sslproxyport != null) {
Property newprop = lb.createChild(Property.class);
newprop.setName("ssl-proxy-port");
newprop.setValue(sslproxyport);
lb.getProperty().add(newprop);
}
param.getLoadBalancer().add(lb);
return Boolean.TRUE;
}
}, loadBalancers);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
use of org.jvnet.hk2.config.RetryableException in project Payara by payara.
the class LDAPAdminAccessConfigurator method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport rep = context.getActionReport();
StringBuilder sb = new StringBuilder();
if (url != null) {
if (!url.startsWith("ldap://") && !url.startsWith("ldaps://")) {
// it's ok to accept just host:port
url = "ldap://" + url;
}
}
if (!pingLDAP(sb)) {
rep.setMessage(sb.toString());
rep.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
configure(sb);
// Realm.getInstance(FIXED_ADMIN_REALM_NAME).refresh();
rep.setMessage(sb.toString());
rep.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure tf) {
rep.setMessage(tf.getMessage());
rep.setActionExitCode(ActionReport.ExitCode.FAILURE);
} catch (PropertyVetoException e) {
rep.setMessage(e.getMessage());
rep.setActionExitCode(ActionReport.ExitCode.FAILURE);
} catch (RetryableException re) {
rep.setMessage(re.getMessage());
rep.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
/*
catch (NoSuchRealmException e) {
ActionReport ar = rep.addSubActionsReport();
ar.setMessage(lsm.getString("realm.not.refreshed"));
ar.setActionExitCode(ActionReport.ExitCode.WARNING);
} catch (BadRealmException e) {
ActionReport ar = rep.addSubActionsReport();
ar.setMessage(lsm.getString("realm.not.refreshed"));
ar.setActionExitCode(ActionReport.ExitCode.WARNING);
}
*/
}
use of org.jvnet.hk2.config.RetryableException in project Payara by payara.
the class LDAPAdminAccessConfigurator method configure.
private void configure(StringBuilder sb) throws TransactionFailure, PropertyVetoException, RetryableException {
// createBackupRealm(sb, getAdminRealm(asc.getSecurityService()), getNewRealmName(asc.getSecurityService()));
Transaction t = new Transaction();
final SecurityService w_asc = t.enroll(asc.getSecurityService());
AdminService w_adminSvc = t.enroll(asc.getAdminService());
deleteRealm(w_asc, sb);
createRealm(w_asc, sb);
configureAdminService(w_adminSvc);
updateSecurityProvider(t, fileRealmProvider, sb);
t.commit();
}
use of org.jvnet.hk2.config.RetryableException in project Payara by payara.
the class ApplicationLifecycle method registerAppInDomainXML.
// register application information in domain.xml
@Override
public void registerAppInDomainXML(final ApplicationInfo applicationInfo, final DeploymentContext context, Transaction t, boolean appRefOnly) throws TransactionFailure {
final Properties appProps = context.getAppProps();
final DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
if (t != null) {
try {
if (!appRefOnly) {
Application app_w = context.getTransientAppMetaData(ServerTags.APPLICATION, Application.class);
// adding the application element
setRestAppAttributes(app_w, appProps);
Applications apps_w = t.enroll(applications);
apps_w.getModules().add(app_w);
if (applicationInfo != null) {
applicationInfo.save(app_w);
}
}
List<String> targets = new ArrayList<String>();
if (!DeploymentUtils.isDomainTarget(deployParams.target)) {
targets.add(deployParams.target);
} else {
List<String> previousTargets = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class);
if (previousTargets == null) {
previousTargets = domain.getAllReferencedTargetsForApplication(deployParams.name);
}
targets = previousTargets;
}
String origVS = deployParams.virtualservers;
Boolean origEnabled = deployParams.enabled;
Properties previousVirtualServers = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, Properties.class);
Properties previousEnabledAttributes = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, Properties.class);
for (String target : targets) {
// first reset the virtualservers, enabled attribute
deployParams.virtualservers = origVS;
deployParams.enabled = origEnabled;
// applicable
if (DeploymentUtils.isDomainTarget(deployParams.target)) {
String vs = previousVirtualServers.getProperty(target);
if (vs != null) {
deployParams.virtualservers = vs;
}
String enabledAttr = previousEnabledAttributes.getProperty(target);
if (enabledAttr != null) {
deployParams.enabled = Boolean.valueOf(enabledAttr);
}
}
if (deployParams.enabled == null) {
deployParams.enabled = Boolean.TRUE;
}
Server servr = domain.getServerNamed(target);
if (servr != null) {
ApplicationRef instanceApplicationRef = domain.getApplicationRefInTarget(deployParams.name, servr.getName());
if (instanceApplicationRef == null) {
// adding the application-ref element to the standalone
// server instance
ConfigBeanProxy servr_w = t.enroll(servr);
// adding the application-ref element to the standalone
// server instance
ApplicationRef appRef = servr_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef, deployParams);
((Server) servr_w).getApplicationRef().add(appRef);
}
}
Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
// adding the application-ref element to the cluster
// and instances
ConfigBeanProxy cluster_w = t.enroll(cluster);
ApplicationRef appRef = cluster_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef, deployParams);
((Cluster) cluster_w).getApplicationRef().add(appRef);
for (Server svr : cluster.getInstances()) {
ConfigBeanProxy svr_w = t.enroll(svr);
ApplicationRef appRef2 = svr_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef2, deployParams);
((Server) svr_w).getApplicationRef().add(appRef2);
}
}
DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
if (dg != null) {
ConfigBeanProxy dg_w = t.enroll(dg);
ApplicationRef appRef = dg_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef, deployParams);
((DeploymentGroup) dg_w).getApplicationRef().add(appRef);
for (Server svr : dg.getInstances()) {
ApplicationRef instanceApplicationRef = domain.getApplicationRefInTarget(deployParams.name, svr.getName());
if (instanceApplicationRef == null) {
ConfigBeanProxy svr_w = t.enroll(svr);
ApplicationRef appRef2 = svr_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef2, deployParams);
((Server) svr_w).getApplicationRef().add(appRef2);
}
}
}
}
} catch (TransactionFailure e) {
t.rollback();
throw e;
} catch (Exception e) {
t.rollback();
throw new TransactionFailure(e.getMessage(), e);
}
try {
t.commit();
} catch (RetryableException e) {
System.out.println("Retryable...");
// TODO : do something meaninful here
t.rollback();
} catch (TransactionFailure e) {
t.rollback();
throw e;
}
}
}
use of org.jvnet.hk2.config.RetryableException in project Payara by payara.
the class ApplicationLifecycle method unregisterTenantWithAppInDomainXML.
@Override
public void unregisterTenantWithAppInDomainXML(final String appName, final String tenantName) throws TransactionFailure, RetryableException {
final com.sun.enterprise.config.serverbeans.Application app = applications.getApplication(appName);
if (app == null) {
throw new IllegalArgumentException("Application " + appName + " not found");
}
final AppTenants appTenants = app.getAppTenants();
final AppTenant appTenant = appTenants.getAppTenant(tenantName);
if (appTenant == null) {
throw new IllegalArgumentException("Tenant " + tenantName + " not provisioned for application " + appName);
}
Transaction t = new Transaction();
final AppTenants appTenants_w = t.enroll(appTenants);
appTenants_w.getAppTenant().remove(appTenant);
t.commit();
}
Aggregations