Search in sources :

Example 1 with Image

use of com.sun.pkg.client.Image in project Payara by payara.

the class UpdateCenterHandlers method getUpdateCenterImage.

public static Image getUpdateCenterImage(String ucDir, boolean force) {
    Image image = null;
    try {
        image = new Image(new File(ucDir));
        if (force || (GuiUtil.getSessionValue(CATALOG_REFRESHED) == null)) {
            image.refreshCatalogs();
            GuiUtil.setSessionValue(CATALOG_REFRESHED, "TRUE");
        }
    } catch (Exception ex) {
        if (force && (image == null)) {
            GuiUtil.getLogger().warning(GuiUtil.getMessage(BUNDLE, "NoImage", new String[] { ucDir }));
        }
    }
    return image;
}
Also used : Image(com.sun.pkg.client.Image) File(java.io.File)

Example 2 with Image

use of com.sun.pkg.client.Image in project Payara by payara.

the class UpdateCenterHandlers method getUcList.

@Handler(id = "getUcList", input = { @HandlerInput(name = "state", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getUcList(HandlerContext handlerCtx) {
    List result = new ArrayList();
    if (Boolean.TRUE.equals(GuiUtil.getSessionValue("_noNetwork"))) {
        handlerCtx.setOutputValue("result", result);
        return;
    }
    try {
        Image img = getUpdateCenterImage();
        if (img == null) {
            handlerCtx.setOutputValue("result", result);
            return;
        }
        String state = (String) handlerCtx.getInputValue("state");
        if (state.equals("update")) {
            handlerCtx.setOutputValue("result", getUpdateDisplayList(img, false));
            return;
        }
        List<Fmri> displayList = null;
        if (state.equals("installed"))
            displayList = getInstalledList(img);
        else if (state.equals("addOn"))
            displayList = getAddOnList(img);
        if (displayList != null) {
            for (Fmri fmri : displayList) {
                Map oneRow = new HashMap();
                try {
                    Manifest manifest = img.getManifest(fmri);
                    oneRow.put("selected", false);
                    oneRow.put("fmri", fmri);
                    oneRow.put("fmriStr", fmri.toString());
                    putInfo(oneRow, "pkgName", fmri.getName());
                    putInfo(oneRow, "version", getPkgVersion(fmri.getVersion()));
                    putInfo(oneRow, "newVersion", "");
                    putInfo(oneRow, "category", getCategory(manifest));
                    putInfo(oneRow, "pkgSize", getPkgSize(manifest));
                    oneRow.put("size", Integer.valueOf(manifest.getPackageSize()));
                    putInfo(oneRow, "auth", fmri.getAuthority());
                    String tooltip = manifest.getAttribute(PKG_SUMMARY);
                    if (GuiUtil.isEmpty(tooltip))
                        tooltip = manifest.getAttribute(DESC);
                    putInfo(oneRow, "tooltip", tooltip);
                    result.add(oneRow);
                } catch (Exception ex) {
                    GuiUtil.getLogger().info("getUcList(): " + ex.getLocalizedMessage());
                    if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception ex1) {
        GuiUtil.getLogger().info("getUcList(): " + ex1.getLocalizedMessage());
        if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
            ex1.printStackTrace();
        }
    }
    handlerCtx.setOutputValue("result", result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Image(com.sun.pkg.client.Image) Manifest(com.sun.pkg.client.Manifest) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Fmri(com.sun.pkg.client.Fmri) Handler(com.sun.jsftemplating.annotation.Handler)

Example 3 with Image

use of com.sun.pkg.client.Image in project Payara by payara.

the class PingService method postConstruct.

// private ActiveModules activeModules;
@Override
public void postConstruct() {
    if (TIMER_INTERVAL <= 0) {
        logger.fine("Domain Ping disabled : " + JVM_OPTION + " <= 0");
        return;
    }
    SystemInfo.UpdateCheckFrequency frequency = SystemInfo.getUpdateCheckFrequency();
    if (frequency.equals(SystemInfo.UpdateCheckFrequency.NEVER)) {
        logger.fine("Domain Ping disabled by Update Center option");
        return;
    }
    try {
        RegistrationUtil.synchUUID();
    } catch (RegistrationException ex) {
        logger.fine("Domain Ping disabled due to UUID exception.");
        logger.fine(ex.getMessage());
        return;
    }
    // activeModules = new ActiveModules(logger, modulesRegistry);
    // Mark the timer as daemon so that it does not hold up appserver shutdown
    final Timer pingTimer = new Timer("PingService", true);
    TimerTask pingTask = new TimerTask() {

        public void run() {
            Image img = null;
            try {
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("product", Version.getProductName().replace(";", ":"));
                map.put("version", getVersionNumber());
                map.put("context", CONTEXT);
                // Disable module status usage tracking.
                // map.put("modules", activeModules.generateModuleStatus());
                img = RegistrationUtil.getUpdateCenterImage();
                img.setMetaData(map);
                img.refreshCatalog(img.getPreferredAuthorityName());
                logger.log(Level.INFO, "Domain Pinged: {0}", img.getPreferredAuthorityName());
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("X-JPkg-Metadata: product: " + map.get("product"));
                    logger.fine("X-JPkg-Metadata: version: " + map.get("version"));
                    logger.fine("X-JPkg-Metadata: context: " + map.get("context"));
                // logger.fine("X-JPkg-Metadata: modules: " + map.get("modules"));
                }
            } catch (Exception e) {
                // exception?
                if (img != null)
                    logger.log(Level.FINE, "Domain Ping: Unable to refresh catalog: {0}", img.getPreferredAuthorityName());
                else
                    logger.log(Level.FINE, "Domain Ping: Unable to refresh catalog.  Null image.");
                logger.fine(e.getMessage());
            } finally // set the time stamp even in case of failure to ping,
            // so that next attempt to ping remains startup agnostic.
            {
                try {
                    setTimeStamp();
                } catch (Exception ex) {
                    logger.fine(ex.getMessage());
                }
            }
        }
    };
    // nextPing is the time after which an initial ping would
    // be attempted during the current server run.  If we are due to
    // ping now we delay the ping by 120 seconds to allow the domain
    // to fully initialize.
    long nextPing = 2 * 60 * 1000;
    try {
        long current = System.currentTimeMillis();
        long lastPing = getTimeStamp();
        // period, regardless of server restarts.
        if (current - lastPing <= ONE_WEEK)
            nextPing = lastPing - current + ONE_WEEK;
        if (nextPing < 0)
            nextPing = 2 * 60 * 1000;
    } catch (Exception ex) {
        logger.fine("Domain Ping: exception computing next ping time.");
        logger.fine(ex.getMessage());
        nextPing = 2 * 60 * 1000L;
    }
    logger.fine("Domain Ping: next ping in " + nextPing / (60 * 1000) + " minutes");
    // ping after nextPing milliseconds and subsequenlty after
    // TIMER_INTERVAL intervals
    pingTimer.schedule(pingTask, nextPing, TIMER_INTERVAL);
}
Also used : RegistrationException(com.sun.enterprise.registration.RegistrationException) SystemInfo(com.sun.pkg.client.SystemInfo) Timer(java.util.Timer) TimerTask(java.util.TimerTask) HashMap(java.util.HashMap) Image(com.sun.pkg.client.Image) RegistrationException(com.sun.enterprise.registration.RegistrationException)

Example 4 with Image

use of com.sun.pkg.client.Image in project Payara by payara.

the class RegistrationUtil method setUpdateCenterUUID.

public static void setUpdateCenterUUID(String instanceURN) throws RegistrationException {
    final String prefix = "urn:st:";
    try {
        Image image = getUpdateCenterImage();
        String[] authorities = image.getAuthorityNames();
        if (instanceURN.startsWith(prefix))
            instanceURN = instanceURN.substring(prefix.length());
        for (String authority : authorities) {
            image.setAuthority(authority, null, instanceURN);
        }
        image.saveConfig();
    } catch (Exception ex) {
        throw new RegistrationException(ex);
    }
}
Also used : RegistrationException(com.sun.enterprise.registration.RegistrationException) Image(com.sun.pkg.client.Image) IOException(java.io.IOException) RegistrationException(com.sun.enterprise.registration.RegistrationException)

Example 5 with Image

use of com.sun.pkg.client.Image in project Payara by payara.

the class InstallationConfigurator method configureUpdatetool.

/* Run configuration steps for update tool component. */
public void configureUpdatetool() throws Exception {
    // set execute permissions for UC utilities
    if (!OSUtils.isWindows()) {
        LOGGER.log(Level.INFO, Msg.get("SETTING_EXECUTE_PERMISSIONS_FOR_UPDATETOOL", null));
        org.glassfish.installer.util.FileUtils.setExecutable(productRef.getInstallLocation() + "/bin/pkg");
        org.glassfish.installer.util.FileUtils.setExecutable(productRef.getInstallLocation() + "/bin/updatetool");
    }
    setupUpdateToolScripts();
    // check whether to bootstrap at all
    if (!ConfigHelper.getBooleanValue("UpdateTool.Configuration.BOOTSTRAP_UPDATETOOL")) {
        LOGGER.log(Level.INFO, Msg.get("SKIPPING_UPDATETOOL_BOOTSTRAP", null));
    } else {
        boolean allowUpdateCheck = ConfigHelper.getBooleanValue("UpdateTool.Configuration.ALLOW_UPDATE_CHECK");
        String proxyHost = configData.get("PROXY_HOST");
        String proxyPort = configData.get("PROXY_PORT");
        // populate bootstrap properties
        Properties props = new Properties();
        if (OSUtils.isWindows()) {
            props.setProperty("image.path", productRef.getInstallLocation().replace('\\', '/'));
        } else {
            props.setProperty("image.path", productRef.getInstallLocation());
        }
        props.setProperty("install.pkg", "true");
        if (!OSUtils.isAix()) {
            props.setProperty("install.updatetool", "true");
        } else {
            props.setProperty("install.updatetool", "false");
        }
        props.setProperty("optin.update.notification", allowUpdateCheck ? "true" : "false");
        props.setProperty("optin.usage.reporting", allowUpdateCheck ? "true" : "false");
        if ((proxyHost.length() > 0) && (proxyPort.length() > 0)) {
            props.setProperty("proxy.URL", "http://" + proxyHost + ":" + proxyPort);
        }
        LOGGER.log(Level.INFO, Msg.get("BOOTSTRAPPING_UPDATETOOL", null));
        LOGGER.log(Level.FINEST, props.toString());
        // proceed to bootstrap if there is an exception
        try {
            SystemInfo.initUpdateToolProps(props);
            Image img = new Image(productRef.getInstallLocation());
            img.refreshCatalogs();
        } catch (Exception e) {
            LOGGER.log(Level.FINEST, e.getMessage());
        }
        // invoke bootstrap
        Bootstrap.main(props, LOGGER);
    }
    // Create the required windows start->menu shortcuts for updatetool.
    if (OSUtils.isWindows()) {
        createUpdatetoolShortCuts();
    }
}
Also used : Properties(java.util.Properties) Image(com.sun.pkg.client.Image)

Aggregations

Image (com.sun.pkg.client.Image)15 Handler (com.sun.jsftemplating.annotation.Handler)8 HashMap (java.util.HashMap)7 TreeMap (java.util.TreeMap)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 SortedMap (java.util.SortedMap)6 Fmri (com.sun.pkg.client.Fmri)5 List (java.util.List)5 Manifest (com.sun.pkg.client.Manifest)3 RegistrationException (com.sun.enterprise.registration.RegistrationException)2 Properties (java.util.Properties)2 SystemInfo (com.sun.pkg.client.SystemInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 SocketAddress (java.net.SocketAddress)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1