Package org.jvnet.hk2.config

Examples of org.jvnet.hk2.config.Transaction


        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();
    }
View Full Code Here


        final String tgt, final boolean appRefOnly)
        throws TransactionFailure {
        ConfigSupport.apply(new SingleConfigCode() {
            public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
                // get the transaction
                Transaction t = Transaction.getTransaction(param);
                if (t!=null) {
                    List<String> targets = new ArrayList<String>();
                    if (!DeploymentUtils.isDomainTarget(tgt)) {
                        targets.add(tgt);   
                    } else {
                        targets = domain.getAllReferencedTargetsForApplication(appName);
                    }

                    Domain dmn;
                    if (param instanceof Domain) {
                        dmn = (Domain)param;
                    } else {
                        return Boolean.FALSE;
                    }

                    for (String target : targets) {
                        Server servr = dmn.getServerNamed(target);
                        if (servr != null) {
                            // remove the application-ref from standalone
                            // server instance
                            ConfigBeanProxy servr_w = t.enroll(servr);
                            for (ApplicationRef appRef :
                                servr.getApplicationRef()) {
                                if (appRef.getRef().equals(appName)) {
                                    ((Server)servr_w).getApplicationRef().remove(
                                        appRef);
                                    break;
                                }
                            }
                        }
             
                        Cluster cluster = dmn.getClusterNamed(target);
                        if (cluster != null) {
                            // remove the application-ref from cluster
                            ConfigBeanProxy cluster_w = t.enroll(cluster);
                            for (ApplicationRef appRef :
                                cluster.getApplicationRef()) {
                                if (appRef.getRef().equals(appName)) {
                                    ((Cluster)cluster_w).getApplicationRef().remove(
                                            appRef);
                                        break;
                                }
                            }

                            // remove the application-ref from cluster instances
                            for (Server svr : cluster.getInstances() ) {
                                ConfigBeanProxy svr_w = t.enroll(svr);
                                for (ApplicationRef appRef :
                                    svr.getApplicationRef()) {
                                    if (appRef.getRef().equals(appName)) {
                                        ((Server)svr_w).getApplicationRef(
                                           ).remove(appRef);
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (!appRefOnly) {
                        // remove application element
                        Applications apps = dmn.getApplications();
                        ConfigBeanProxy apps_w = t.enroll(apps);
                        for (ApplicationName module : apps.getModules()) {
                            if (module.getName().equals(appName)) {
                                ((Applications)apps_w).getModules().remove(module);
                                break;
                            }
View Full Code Here

    public void updateAppEnabledAttributeInDomainXML(final String appName,
        final String target, final boolean enabled) throws TransactionFailure {
        ConfigSupport.apply(new SingleConfigCode() {
            public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
                // get the transaction
                Transaction t = Transaction.getTransaction(param);
                if (t!=null) {
                    Domain dmn;
                    if (param instanceof Domain) {
                        dmn = (Domain)param;
                    } else {
                        return Boolean.FALSE;
                    }

                    if (enabled || DeploymentUtils.isDomainTarget(target)) {
                        Application app = dmn.getApplications().getApplication(appName);
                        ConfigBeanProxy app_w = t.enroll(app);
                       ((Application)app_w).setEnabled(String.valueOf(enabled));

                    }

                    List<String> targets = new ArrayList<String>();
                    if (!DeploymentUtils.isDomainTarget(target)) {
                        targets.add(target);
                    } else {
                        targets = domain.getAllReferencedTargetsForApplication(appName);
                    }

                    for (String target : targets) {
                        Server servr = dmn.getServerNamed(target);
                        if (servr != null) {
                            // update the application-ref from standalone
                            // server instance
                            for (ApplicationRef appRef :
                                servr.getApplicationRef()) {
                                if (appRef.getRef().equals(appName)) {
                                    ConfigBeanProxy appRef_w = t.enroll(appRef);
                                    ((ApplicationRef)appRef_w).setEnabled(String.valueOf(enabled));
                                    break;
                                }
                            }
                            updateClusterAppRefWithInstanceUpdate(t, servr, appName, enabled);
                        }
                        Cluster cluster = dmn.getClusterNamed(target);
                        if (cluster != null) {
                            // update the application-ref from cluster
                            for (ApplicationRef appRef :
                                cluster.getApplicationRef()) {
                                if (appRef.getRef().equals(appName)) {
                                    ConfigBeanProxy appRef_w = t.enroll(appRef);
                                    ((ApplicationRef)appRef_w).setEnabled(String.valueOf(enabled));
                                    break;
                                }
                            }

                            // update the application-ref from cluster instances
                            for (Server svr : cluster.getInstances() ) {
                                for (ApplicationRef appRef :
                                    svr.getApplicationRef()) {
                                    if (appRef.getRef().equals(appName)) {
                                        ConfigBeanProxy appRef_w = t.enroll(appRef);
                                        ((ApplicationRef)appRef_w).setEnabled(String.valueOf(enabled));
                                        break;
                                    }
                                }
                            }
View Full Code Here

    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();
    }
View Full Code Here

        /*
         * If an app client has a property setting for javaWebStartEnabled we
         * convert it to java-web-start-enabled which is the documented name.
         * App clients can be either applications or modules within an EAR.
         */
        final Transaction t = new Transaction();
        try {
            for (Application app : domain.getApplications().getApplications()) {
                System.out.println("Checking app " + app.getName());
                Application app_w = null;
                Property oldSetting = app.getProperty(V3_0_1_JAVA_WEB_START_ENABLED_PROPERTY_NAME);
                if (oldSetting != null) {
                    logger.log(Level.INFO, "For application {0} converting property {1} to {2}",
                    new Object[] {
                        app.getName(),
                        V3_0_1_JAVA_WEB_START_ENABLED_PROPERTY_NAME,
                        GF3_1_JAVA_WEB_START_ENABLED_PROPERTY_NAME});
                    app_w = t.enroll(app);
                    addProperty(GF3_1_JAVA_WEB_START_ENABLED_PROPERTY_NAME,
                            oldSetting.getValue(), app_w);
                    app_w.getProperty().remove(oldSetting);
                }
                for (Module mod : app.getModule()) {
                    if (mod.getEngine(APPCLIENT_SNIFFER_NAME) != null) {
                        /*
                         * This is an app client.  See if the client has
                         * a property setting using the old name.
                         */
                        oldSetting = mod.getProperty(V3_0_1_JAVA_WEB_START_ENABLED_PROPERTY_NAME);
                        if (oldSetting != null) {
                            logger.log(Level.INFO, "For application {0}/module {1} converting property {2} to {3}",
                                new Object[] {
                                    app.getName(),
                                    mod.getName(),
                                    V3_0_1_JAVA_WEB_START_ENABLED_PROPERTY_NAME,
                                    GF3_1_JAVA_WEB_START_ENABLED_PROPERTY_NAME});
                            final Module mod_w = t.enroll(mod);
                            addProperty(GF3_1_JAVA_WEB_START_ENABLED_PROPERTY_NAME,
                                    oldSetting.getValue(),
                                    mod_w);
                            mod_w.getProperty().remove(oldSetting);
                        }
                    }
                }

            }
            t.commit();
        } catch (Exception ex) {
            t.rollback();
            throw new RuntimeException("Error upgrading application", ex);
        }
    }
View Full Code Here

        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);
        }
    }
View Full Code Here

    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();
    }
View Full Code Here

        ConfigSupport.apply(new SingleConfigCode<Domain>() {
            @Override
            public Object run(Domain domain_w) throws PropertyVetoException, TransactionFailure {

                // get the transaction
                final Transaction t = Transaction.getTransaction(domain_w);
                final TopLevelContext topLevelContext =
                        new TopLevelContext(t, domain_w);
                if (t!=null) {

                    /*
                     * Do the work on just the secure-admin element.
                     */
                    for (Iterator<Work<TopLevelContext>> it = secureAdminSteps(); it.hasNext();) {
                        final Work<TopLevelContext> step = it.next();
                        if ( ! step.run(topLevelContext) ) {
                            t.rollback();
                            return Boolean.FALSE;
                        }
                    }

                    /*
                     * Now apply the required changes to the admin listener
                     * in the DAS configuration.
                     */
                    final Configs configs = domain_w.getConfigs();
                    final Config c = configs.getConfigByName(DAS_CONFIG_NAME);
                    final Config c_w = t.enroll(c);
                    ConfigLevelContext configLevelContext =
                            new ConfigLevelContext(topLevelContext, c_w);
                    for (Iterator<Work<ConfigLevelContext>> it = perConfigSteps(); it.hasNext();) {
                        final Work<ConfigLevelContext> step = it.next();
                        if ( ! step.run(configLevelContext)) {
                            t.rollback();
                            return Boolean.FALSE;
                        }
                    }

                }
View Full Code Here

    private Properties startupArgs = null;
   
   
    final protected Transaction transaction() {
        if (t == null) {
            t = new Transaction();
        }
        return t;
    }
View Full Code Here

    // in the domain.xml
    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;
    }
View Full Code Here

TOP

Related Classes of org.jvnet.hk2.config.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.