001/*
002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu, jcarsique
018 */
019package org.nuxeo.connect.update.live;
020
021import java.io.IOException;
022
023import org.nuxeo.common.Environment;
024import org.nuxeo.connect.update.PackageException;
025import org.nuxeo.connect.update.PackageUpdateService;
026import org.nuxeo.connect.update.standalone.StandaloneUpdateService;
027import org.nuxeo.connect.update.task.live.LiveInstallTask;
028import org.nuxeo.connect.update.task.live.LiveUninstallTask;
029import org.nuxeo.connect.update.task.live.commands.Deploy;
030import org.nuxeo.connect.update.task.live.commands.DeployConfig;
031import org.nuxeo.connect.update.task.live.commands.Flush;
032import org.nuxeo.connect.update.task.live.commands.FlushCoreCache;
033import org.nuxeo.connect.update.task.live.commands.FlushJaasCache;
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.UpdateAndDeploy;
039import org.nuxeo.connect.update.task.update.Rollback;
040import org.nuxeo.connect.update.task.update.Update;
041import org.nuxeo.runtime.reload.NuxeoRestart;
042
043/**
044 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
045 */
046public class UpdateServiceImpl extends StandaloneUpdateService implements PackageUpdateService {
047
048    public UpdateServiceImpl() throws IOException {
049        super(Environment.getDefault());
050    }
051
052    @Override
053    protected void addCommands() {
054        super.addCommands();
055        addCommand(FlushCoreCache.ID, FlushCoreCache.class);
056        addCommand(FlushJaasCache.ID, FlushJaasCache.class);
057        addCommand(Flush.ID, Flush.class);
058
059        addCommand(ReloadProperties.ID, ReloadProperties.class);
060
061        addCommand(Deploy.ID, Deploy.class);
062        addCommand(Undeploy.ID, Undeploy.class);
063
064        addCommand(DeployConfig.ID, DeployConfig.class);
065        addCommand(UndeployConfig.ID, UndeployConfig.class);
066
067        // override the update command to add hot reload support
068        addCommand(Update.ID, UpdateAndDeploy.class);
069        addCommand(Rollback.ID, RollbackAndUndeploy.class);
070    }
071
072    @Override
073    public void restart() throws PackageException {
074        try {
075            NuxeoRestart.restart();
076        } catch (IOException e) {
077            throw new PackageException("Failed to restart Nuxeo", e);
078        }
079    }
080
081    @Override
082    public String getDefaultInstallTaskType() {
083        return LiveInstallTask.class.getName();
084    }
085
086    @Override
087    public String getDefaultUninstallTaskType() {
088        return LiveUninstallTask.class.getName();
089    }
090
091}