org.yamcs.server.cli.XtceDbCli Maven / Gradle / Ivy
package org.yamcs.server.cli;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.yamcs.ConfigurationException;
import org.yamcs.YConfiguration;
import org.yamcs.xtce.XtceDb;
import org.yamcs.xtceproc.XtceDbFactory;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.error.YAMLException;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
@Parameters(commandDescription = "Provides information about the xtce database")
public class XtceDbCli extends Command {
@Parameter(names="-f", required=false, description ="Use this file instead of default mdb.yaml")
String mdbConfigFile;
public XtceDbCli(Command parent) {
super("xtcedb", parent);
addSubCommand(new XtceDbListConfigs());
addSubCommand(new XtceDbPrint());
addSubCommand(new XtceDbVerify());
}
private XtceDb getXtceDb(String configSection) {
XtceDb xtcedb;
if(mdbConfigFile==null) {
xtcedb = XtceDbFactory.createInstanceByConfig(configSection);
} else {
Yaml yaml=new Yaml();
try (InputStream is = new FileInputStream(mdbConfigFile)){
Object o = yaml.load(is);
if(o==null) {
throw new ConfigurationException(mdbConfigFile, mdbConfigFile+": file is empty!?");
} else if(!(o instanceof Map, ?>)) {
throw new ConfigurationException(mdbConfigFile, mdbConfigFile+": top level structure must be a map and not a "+o);
}
o = ((Map)o).get(configSection);
if(o==null) {
throw new ConfigurationException(mdbConfigFile, mdbConfigFile+": does not contain a mapping for "+configSection);
} else if(!(o instanceof List>)) {
throw new ConfigurationException(mdbConfigFile, mdbConfigFile+": mapping for "+configSection+" must be a list and not a "+o.getClass());
}
List