com.qwazr.scheduler.SchedulerServiceImpl Maven / Gradle / Ivy
Show all versions of qwazr-scheduler Show documentation
/*
* Copyright 2015-2017 Emmanuel Keller / QWAZR
*
* 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.qwazr.scheduler;
import com.qwazr.scripts.ScriptRunStatus;
import com.qwazr.server.AbstractServiceImpl;
import com.qwazr.server.ServerException;
import com.qwazr.utils.LoggerUtils;
import javax.ws.rs.WebApplicationException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.TreeMap;
import java.util.logging.Logger;
class SchedulerServiceImpl extends AbstractServiceImpl implements SchedulerServiceInterface {
private final static Logger LOGGER = LoggerUtils.getLogger(SchedulerServiceImpl.class);
private volatile SchedulerManager schedulerManager;
SchedulerServiceImpl(SchedulerManager schedulerManager) {
this.schedulerManager = schedulerManager;
}
@Override
public TreeMap list() {
return schedulerManager.getSchedulers();
}
@Override
public SchedulerStatus get(final String schedulerName, final ActionEnum action) {
try {
final SchedulerDefinition schedulerDef = schedulerManager.getScheduler(schedulerName);
final List statusList = schedulerManager.getStatusList(schedulerName);
if (action != null && action == ActionEnum.run)
return new SchedulerStatus(schedulerDef,
schedulerManager.executeScheduler(schedulerName, schedulerDef));
else
return new SchedulerStatus(schedulerDef, statusList);
} catch (WebApplicationException | IOException | URISyntaxException | ServerException e) {
throw ServerException.getJsonException(LOGGER, e);
}
}
}