2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.dbmap;
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
27 import com.google.common.base.Preconditions;
28 import com.google.common.base.Predicate;
29 import com.google.common.collect.Iterators;
30 import com.thinkaurelius.titan.diskstorage.configuration.ConfigElement;
31 import com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration;
32 import org.apache.commons.configuration.ConfigurationException;
33 import org.apache.commons.configuration.PropertiesConfiguration;
34 import org.apache.commons.lang.StringUtils;
37 import java.io.FileNotFoundException;
38 import java.lang.management.ManagementFactory;
39 import java.util.Iterator;
40 import java.util.Objects;
41 import java.util.regex.Pattern;
43 import static com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.*;
46 * For building a config that TitanFactory.open can use with an identifiable graph.unique-instance-id
48 public class AAIGraphConfig {
50 private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIGraphConfig.class);
52 private AAIGraphConfig(){};
54 public PropertiesConfiguration getCc(String configPath, String graphType, String service) throws ConfigurationException, FileNotFoundException {
56 PropertiesConfiguration cc = this.loadTitanPropFile(configPath);
58 String uid = ManagementFactory.getRuntimeMXBean().getName() + "_" + service + "_" + graphType + "_" + System.currentTimeMillis();
59 for (char c : ConfigElement.ILLEGAL_CHARS) {
60 uid = StringUtils.replaceChars(uid, c,'_');
63 cc.addProperty("graph.unique-instance-id", uid);
69 private PropertiesConfiguration loadTitanPropFile(String shortcutOrFile) throws ConfigurationException, FileNotFoundException {
70 File file = new File(shortcutOrFile);
72 PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
73 propertiesConfiguration.setAutoSave(false);
74 propertiesConfiguration.load(shortcutOrFile);
75 return propertiesConfiguration;
77 throw new FileNotFoundException(shortcutOrFile);
81 public static class Builder {
82 private String configPath;
83 private String graphType;
84 private String service;
86 public Builder(String configPath) {
87 this.configPath = configPath;
90 public Builder withGraphType(String graphType) {
91 this.graphType = Objects.toString(graphType, "NA");
95 public Builder forService(String service) {
96 this.service = Objects.toString(service, "NA");
100 public PropertiesConfiguration buildConfiguration() throws ConfigurationException, FileNotFoundException {
101 return new AAIGraphConfig().getCc(this.configPath, this.graphType, this.service);