
org.glassfish.admingui.common.util.DeployUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of console-common Show documentation
Show all versions of console-common Show documentation
This bundle contains common code that may be shared across plugins.
The newest version!
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* DeploymentHandler.java
*
*/
package org.glassfish.admingui.common.util;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
/**
*
* @author anilam
*/
public class DeployUtil {
/* reload application for each target. If the app is disabled for the target, it is an no-op.
* otherwise, the app is disabled and then enabled to force the reload.
*/
static public boolean reloadApplication(String appName, List targets, HandlerContext handlerCtx){
try{
String decodedName = URLDecoder.decode(appName, "UTF-8");
List clusters = TargetUtil.getClusters();
String clusterEndpoint = GuiUtil.getSessionValue("REST_URL")+"/clusters/cluster/";
String serverEndpoint = GuiUtil.getSessionValue("REST_URL")+"/servers/server/";
for(String targetName : targets){
String endpoint ;
if (clusters.contains(targetName)){
endpoint = clusterEndpoint + targetName + "/application-ref/" + decodedName ;
}else{
endpoint = serverEndpoint + targetName + "/application-ref/" + decodedName ;
}
String status = (String) RestUtil.getAttributesMap(endpoint).get("enabled");
if ( Boolean.parseBoolean(status)){
Map attrs = new HashMap();
attrs.put("enabled", "false");
RestUtil.restRequest(endpoint, attrs, "POST", null, false, true);
attrs.put("enabled", "true");
RestUtil.restRequest(endpoint, attrs, "POST", null, false, true);
}
}
}catch(Exception ex){
GuiUtil.handleError(handlerCtx, ex.getMessage());
return false;
}
return true;
}
//This method returns the list of targets (clusters and standalone instances) of any deployed application
static public List getApplicationTarget(String appName, String ref){
List targets = new ArrayList();
try{
//check if any cluster has this application-ref
List clusters = TargetUtil.getClusters();
for(String oneCluster: clusters){
List appRefs = new ArrayList(RestUtil.getChildMap(GuiUtil.getSessionValue("REST_URL")+"/clusters/cluster/"+oneCluster+"/"+ref).keySet());
if (appRefs.contains(appName)){
targets.add(oneCluster);
}
}
List servers = TargetUtil.getStandaloneInstances();
servers.add("server");
for(String oneServer: servers){
List appRefs = new ArrayList(RestUtil.getChildMap(GuiUtil.getSessionValue("REST_URL") + "/servers/server/" + oneServer + "/" + ref).keySet());
if (appRefs.contains(appName)){
targets.add(oneServer);
}
}
}catch(Exception ex){
GuiUtil.getLogger().info(GuiUtil.getCommonMessage("log.error.appTarget") + ex.getLocalizedMessage());
if (GuiUtil.getLogger().isLoggable(Level.FINE)){
ex.printStackTrace();
}
}
return targets;
}
static public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy