com.github.ipaas.ideploy.agent.handler.RollbackCodeHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.github.ipaas.ideploy.agent.handler.RollbackCodeHandler.java

Source

/**
 * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *    *      http://www.apache.org/licenses/LICENSE-2.0  *    * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License..
 */

package com.github.ipaas.ideploy.agent.handler;

import java.io.File;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tmatesoft.svn.core.wc.SVNRevision;

import com.github.ipaas.ideploy.agent.CrsCmdHandlerWithFeed;
import com.github.ipaas.ideploy.agent.util.SVNUtil;
import com.github.ipaas.ideploy.agent.util.UpdateCodeUtil;
import com.github.ipaas.ifw.util.JsonUtil;
import com.github.ipaas.ifw.util.StringUtil;

/**
 * ?
 * 
 * @author wudg
 */

public class RollbackCodeHandler extends CrsCmdHandlerWithFeed {

    private static Logger logger = LoggerFactory.getLogger(RollbackCodeHandler.class);

    @Override
    public void execute(String flowId, String cmd, Map<String, Object> params, BundleContext bundleContext)
            throws Exception {

        String doingCodeVerPath = (String) params.get("doingCodeVerPath");
        String usingCodeVerPath = (String) params.get("usingCodeVerPath");

        String deployPath = (String) params.get("deployPath");
        logger.debug(" params:" + JsonUtil.toJson(params));
        if (StringUtil.isNullOrBlank(usingCodeVerPath)) {// ,???,?
            File localBkFile = new File(String.valueOf(params.get("localBkPath")));
            File appRootFile = new File(deployPath);
            if (appRootFile.exists()) {
                FileUtils.cleanDirectory(appRootFile);// ?
            }
            if (!localBkFile.exists()) {
                logger.error("?:" + localBkFile.getAbsolutePath());
                throw new Exception("?,?!");
            }
            FileUtils.copyDirectory(localBkFile, appRootFile);
            logger.debug("??");
            return;
        }

        String savePath = String.valueOf(params.get("savePath"));
        long headRev = SVNRevision.HEAD.getNumber();

        Integer hostStatus = Integer.valueOf("" + params.get("hostStatus"));

        if (hostStatus == 1) {// ,??SVN?
            SVNUtil.getDeta4UpdateAll(usingCodeVerPath, headRev, savePath);
        } else {
            // ?? ?
            SVNUtil.getDelta(doingCodeVerPath, headRev, usingCodeVerPath, headRev, savePath);
        }

        // ?
        UpdateCodeUtil.updateCode(savePath, deployPath);
    }
}