SystemApplications sApps = domain.getSystemApplications();
if (sApps != null && sApps.getModules().size()>0) {
return;
}
Transaction t = new Transaction();
try {
ConfigBeanProxy apps_w = t.enroll(apps);
// 1. transform all old application elements to new
// application element
// connector module
for (ConnectorModule connectorModule :
apps.getModules(ConnectorModule.class)) {
// adding the new application element
Application app = apps_w.createChild(
Application.class);
app.setName(connectorModule.getName());
app.setLocation(getLocationAsURIString(
connectorModule.getLocation()));
app.setObjectType(connectorModule.getObjectType());
app.setDescription(connectorModule.getDescription());
app.setEnabled(connectorModule.getEnabled());
app.setDirectoryDeployed(
connectorModule.getDirectoryDeployed());
for (Property property :
connectorModule.getProperty()) {
Property prop =
app.createChild(Property.class);
prop.setName(property.getName());
prop.setValue(property.getValue());
app.getProperty().add(prop);
}
Property prop =
app.createChild(Property.class);
prop.setName(MODULE_TYPE);
prop.setValue(ServerTags.CONNECTOR_MODULE);
app.getProperty().add(prop);
// removing the old connector module
((Applications)apps_w).getModules().remove(connectorModule);
// adding the new application element
((Applications)apps_w).getModules().add(app);
}
// ejb-module
for (EjbModule ejbModule :
apps.getModules(EjbModule.class)) {
// adding the new application element
Application app = apps_w.createChild(
Application.class);
app.setName(ejbModule.getName());
app.setLocation(getLocationAsURIString(
ejbModule.getLocation()));
app.setObjectType(ejbModule.getObjectType());
app.setDescription(ejbModule.getDescription());
app.setEnabled(ejbModule.getEnabled());
app.setDirectoryDeployed(
ejbModule.getDirectoryDeployed());
app.setLibraries(ejbModule.getLibraries());
app.setAvailabilityEnabled(
ejbModule.getAvailabilityEnabled());
for (Property property :
ejbModule.getProperty()) {
Property prop =
app.createChild(Property.class);
prop.setName(property.getName());
prop.setValue(property.getValue());
app.getProperty().add(prop);
}
Property prop =
app.createChild(Property.class);
prop.setName(MODULE_TYPE);
prop.setValue(ServerTags.EJB_MODULE);
app.getProperty().add(prop);
// removing the old ejb module
((Applications)apps_w).getModules().remove(ejbModule);
// adding the new application element
((Applications)apps_w).getModules().add(app);
}
// web-module
for (WebModule webModule :
apps.getModules(WebModule.class)) {
// adding the new application element
Application app = apps_w.createChild(
Application.class);
app.setName(webModule.getName());
app.setLocation(getLocationAsURIString(
webModule.getLocation()));
app.setObjectType(webModule.getObjectType());
app.setDescription(webModule.getDescription());
app.setEnabled(webModule.getEnabled());
app.setDirectoryDeployed(
webModule.getDirectoryDeployed());
app.setLibraries(webModule.getLibraries());
app.setContextRoot(webModule.getContextRoot());
app.setAvailabilityEnabled(
webModule.getAvailabilityEnabled());
for (Property property :
webModule.getProperty()) {
Property prop =
app.createChild(Property.class);
prop.setName(property.getName());
prop.setValue(property.getValue());
app.getProperty().add(prop);
}
Property prop =
app.createChild(Property.class);
prop.setName(MODULE_TYPE);
prop.setValue(ServerTags.WEB_MODULE);
app.getProperty().add(prop);
// removing the old web module
((Applications)apps_w).getModules().remove(webModule);
// adding the new application element
((Applications)apps_w).getModules().add(app);
}
// appclient-module
for (AppclientModule appclientModule :
apps.getModules(AppclientModule.class)) {
// adding the new application element
Application app = apps_w.createChild(
Application.class);
app.setName(appclientModule.getName());
app.setLocation(getLocationAsURIString(
appclientModule.getLocation()));
app.setObjectType("user");
app.setDescription(appclientModule.getDescription());
app.setEnabled("true");
app.setDirectoryDeployed(
appclientModule.getDirectoryDeployed());
for (Property property :
appclientModule.getProperty()) {
Property prop =
app.createChild(Property.class);
prop.setName(property.getName());
prop.setValue(property.getValue());
app.getProperty().add(prop);
}
Property prop =
app.createChild(Property.class);
prop.setName(ServerTags.JAVA_WEB_START_ENABLED);
prop.setValue(
appclientModule.getJavaWebStartEnabled());
app.getProperty().add(prop);
Property prop2 =
app.createChild(Property.class);
prop2.setName(MODULE_TYPE);
prop2.setValue(ServerTags.APPCLIENT_MODULE);
app.getProperty().add(prop2);
// removing the old appclient module
((Applications)apps_w).getModules().remove(appclientModule);
// adding the new application element
((Applications)apps_w).getModules().add(app);
}
// j2ee-application
for (J2eeApplication j2eeApp :
apps.getModules(J2eeApplication.class)) {
// adding the new application element
Application app = apps_w.createChild(
Application.class);
app.setName(j2eeApp.getName());
app.setLocation(getLocationAsURIString(
j2eeApp.getLocation()));
app.setObjectType(j2eeApp.getObjectType());
app.setDescription(j2eeApp.getDescription());
app.setEnabled(j2eeApp.getEnabled());
app.setDirectoryDeployed(
j2eeApp.getDirectoryDeployed());
app.setLibraries(j2eeApp.getLibraries());
app.setAvailabilityEnabled(
j2eeApp.getAvailabilityEnabled());
for (Property property :
j2eeApp.getProperty()) {
Property prop =
app.createChild(Property.class);
prop.setName(property.getName());
prop.setValue(property.getValue());
app.getProperty().add(prop);
}
Property prop =
app.createChild(Property.class);
prop.setName(ServerTags.JAVA_WEB_START_ENABLED);
prop.setValue(
j2eeApp.getJavaWebStartEnabled());
app.getProperty().add(prop);
Property prop2 =
app.createChild(Property.class);
prop2.setName(MODULE_TYPE);
prop2.setValue(ServerTags.J2EE_APPLICATION);
app.getProperty().add(prop2);
// removing the old j2eeapplication module
((Applications)apps_w).getModules().remove(j2eeApp);
// adding the new application element
((Applications)apps_w).getModules().add(app);
}
// extension-module
if (apps.getModules(
ExtensionModule.class).size() > 0) {
Logger.getAnonymousLogger().log(Level.WARNING, "Ignoring extension-module elements. GlassFish v3 does not support extension modules from GlassFish v2.");
}
for (ExtensionModule extensionModule :
apps.getModules(ExtensionModule.class)) {
// removing the extension module
((Applications)apps_w).getModules().remove(extensionModule);
}
// lifecycle-module
for (LifecycleModule lifecycleModule :
apps.getModules(LifecycleModule.class)) {
// adding the new application element
Application app = apps_w.createChild(
Application.class);
app.setName(lifecycleModule.getName());
app.setObjectType(lifecycleModule.getObjectType());
app.setDescription(lifecycleModule.getDescription());
app.setEnabled(lifecycleModule.getEnabled());
for (Property property :
lifecycleModule.getProperty()) {
Property prop =
app.createChild(Property.class);
prop.setName(property.getName());
prop.setValue(property.getValue());
app.getProperty().add(prop);
}
Property prop =
app.createChild(Property.class);
prop.setName(ServerTags.CLASS_NAME);
prop.setValue(
lifecycleModule.getClassName());
app.getProperty().add(prop);
if (lifecycleModule.getClasspath() != null) {
Property prop1 =
app.createChild(Property.class);
prop1.setName(ServerTags.CLASSPATH);
prop1.setValue(
lifecycleModule.getClasspath());
app.getProperty().add(prop1);
}
if (lifecycleModule.getLoadOrder() != null) {
Property prop2 =
app.createChild(Property.class);
prop2.setName(ServerTags.LOAD_ORDER);
prop2.setValue(
lifecycleModule.getLoadOrder());
app.getProperty().add(prop2);
}
Property prop3 =
app.createChild(Property.class);
prop3.setName(ServerTags.IS_FAILURE_FATAL);
prop3.setValue(
lifecycleModule.getIsFailureFatal());
app.getProperty().add(prop3);
Property prop4 =
app.createChild(Property.class);
prop4.setName(ServerTags.IS_LIFECYCLE);
prop4.setValue("true");
app.getProperty().add(prop4);
// removing the old lifecycle module
((Applications)apps_w).getModules().remove(lifecycleModule);
// adding the new application element
((Applications)apps_w).getModules().add(app);
}
// custom mbean
if (apps.getModules(Mbean.class).size() > 0) {
Logger.getAnonymousLogger().log(Level.WARNING, "Ignoring mbean elements. GlassFish v3 does not support custom MBeans from GlassFish v2.");
}
for (Mbean mbean :
apps.getModules(Mbean.class)) {
// removing the custom mbean
((Applications)apps_w).getModules().remove(mbean);
}
// 2. remove all system apps
List<String> systemAppNames = new ArrayList<String>();
for (Application application :
((Applications)apps_w).getModules(Application.class)) {
if (application.getObjectType().startsWith(
"system-")) {
((Applications)apps_w).getModules().remove(application);
systemAppNames.add(application.getName());
}
}
List<String> allTargets = domain.getAllTargets();
for (String target : allTargets) {
Server servr = domain.getServerNamed(target);
if (servr != null) {
ConfigBeanProxy servr_w = t.enroll(servr);
List<ApplicationRef> appRefs = servr.getApplicationRef();
for (ApplicationRef appRef : appRefs) {
if (systemAppNames.contains(appRef.getRef())) {
((Server)servr_w).getApplicationRef().remove(appRef);
}
}
continue;
}
Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
ConfigBeanProxy cluster_w = t.enroll(cluster);
// remove the application-ref from cluster
List<ApplicationRef> appRefs = cluster.getApplicationRef();
for (ApplicationRef appRef : appRefs) {
if (systemAppNames.contains(appRef.getRef())) {
((Cluster)cluster_w).getApplicationRef().remove(appRef);
}
}
// remove the application-ref from cluster
// instances
for (Server svr : cluster.getInstances() ) {
ConfigBeanProxy svr_w = t.enroll(svr);
List<ApplicationRef> appRefs2 = svr.getApplicationRef();
for (ApplicationRef appRef2 : appRefs2) {
if (systemAppNames.contains(appRef2.getRef())) {
((Server)svr_w).getApplicationRef().remove(appRef2);
}
}
}
}
}
// 3. add a new empty system-apps element
// for v3 system apps
ConfigBeanProxy domain_w = t.enroll(domain);
SystemApplications systemApps = domain_w.createChild(
SystemApplications.class);
((Domain)domain_w).setSystemApplications(systemApps);
} catch(TransactionFailure tf) {
t.rollback();
Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading application", tf);
throw new RuntimeException(tf);
} catch (Exception e) {
t.rollback();
throw new RuntimeException(e);
}
try {
t.commit();
} catch (RetryableException e) {
t.rollback();
} catch (TransactionFailure e) {
t.rollback();
throw new RuntimeException(e);
}
}