001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu, jcarsique
016 */
017package org.nuxeo.connect.update.live;
018
019import java.io.IOException;
020
021import org.nuxeo.common.Environment;
022import org.nuxeo.connect.update.PackageException;
023import org.nuxeo.connect.update.PackageUpdateService;
024import org.nuxeo.connect.update.standalone.StandaloneUpdateService;
025import org.nuxeo.connect.update.task.live.LiveInstallTask;
026import org.nuxeo.connect.update.task.live.LiveUninstallTask;
027import org.nuxeo.connect.update.task.live.commands.Deploy;
028import org.nuxeo.connect.update.task.live.commands.DeployConfig;
029import org.nuxeo.connect.update.task.live.commands.Flush;
030import org.nuxeo.connect.update.task.live.commands.FlushCoreCache;
031import org.nuxeo.connect.update.task.live.commands.FlushJaasCache;
032import org.nuxeo.connect.update.task.live.commands.Install;
033import org.nuxeo.connect.update.task.live.commands.LoadJar;
034import org.nuxeo.connect.update.task.live.commands.ReloadProperties;
035import org.nuxeo.connect.update.task.live.commands.RollbackAndUndeploy;
036import org.nuxeo.connect.update.task.live.commands.Undeploy;
037import org.nuxeo.connect.update.task.live.commands.UndeployConfig;
038import org.nuxeo.connect.update.task.live.commands.Uninstall;
039import org.nuxeo.connect.update.task.live.commands.UnloadJar;
040import org.nuxeo.connect.update.task.live.commands.UpdateAndDeploy;
041import org.nuxeo.connect.update.task.update.Rollback;
042import org.nuxeo.connect.update.task.update.Update;
043import org.nuxeo.runtime.reload.NuxeoRestart;
044
045/**
046 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
047 */
048public class UpdateServiceImpl extends StandaloneUpdateService implements PackageUpdateService {
049
050    public UpdateServiceImpl() throws IOException {
051        super(Environment.getDefault());
052    }
053
054    @Override
055    protected void addCommands() {
056        super.addCommands();
057        addCommand(Install.ID, Install.class);
058        addCommand(Uninstall.ID, Uninstall.class);
059        addCommand(FlushCoreCache.ID, FlushCoreCache.class);
060        addCommand(FlushJaasCache.ID, FlushJaasCache.class);
061        addCommand(Flush.ID, Flush.class);
062
063        addCommand(ReloadProperties.ID, ReloadProperties.class);
064
065        addCommand(Deploy.ID, Deploy.class);
066        addCommand(Undeploy.ID, Undeploy.class);
067
068        addCommand(DeployConfig.ID, DeployConfig.class);
069        addCommand(UndeployConfig.ID, UndeployConfig.class);
070
071        addCommand(LoadJar.ID, LoadJar.class);
072        addCommand(UnloadJar.ID, UnloadJar.class);
073
074        // override the update command to add hot reload support
075        addCommand(Update.ID, UpdateAndDeploy.class);
076        addCommand(Rollback.ID, RollbackAndUndeploy.class);
077    }
078
079    @Override
080    public void restart() throws PackageException {
081        try {
082            NuxeoRestart.restart();
083        } catch (IOException e) {
084            throw new PackageException("Failed to restart Nuxeo", e);
085        }
086    }
087
088    @Override
089    public String getDefaultInstallTaskType() {
090        return LiveInstallTask.class.getName();
091    }
092
093    @Override
094    public String getDefaultUninstallTaskType() {
095        return LiveUninstallTask.class.getName();
096    }
097
098}