001/** 002 * Copyright 2016 Tampere University of Technology, Pori Department 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 */ 016package service.tut.pori.apilta; 017 018import java.util.Properties; 019 020import org.apache.commons.lang3.StringUtils; 021import org.apache.log4j.Logger; 022 023import core.tut.pori.context.ServiceInitializer; 024import core.tut.pori.properties.SystemProperty; 025 026/** 027 * Apilta Properties 028 * 029 */ 030public class ApiltaProperties extends SystemProperty { 031 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA = PROPERTY_SERVICE_PORI+".apilta"; 032 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_ALERT_REMOVE_THRESHOLD = PROPERTY_SERVICE_TUT_PORI_APILTA+".alert.default_remove_threshold"; 033 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_ALERT_VALIDITY_TIME = PROPERTY_SERVICE_TUT_PORI_APILTA+".alert.default_validity_time"; 034 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_CONTAINER = PROPERTY_SERVICE_TUT_PORI_APILTA+".swift.container"; 035 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_CREDENTIAL = PROPERTY_SERVICE_TUT_PORI_APILTA+".swift.credential"; 036 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_DEFAULT_EXPIRATION_TIME = PROPERTY_SERVICE_TUT_PORI_APILTA+".swift.default_expiration_time"; 037 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_ENDPOINT = PROPERTY_SERVICE_TUT_PORI_APILTA+".swift.endpoint"; 038 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_IDENTITY = PROPERTY_SERVICE_TUT_PORI_APILTA+".swift.identity"; 039 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_PREFERRED_REGION = PROPERTY_SERVICE_TUT_PORI_APILTA+".swift.preferred_region"; 040 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_PROVIDER = PROPERTY_SERVICE_TUT_PORI_APILTA+".swift.provider"; 041 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_PUBLIC_ENDPOINT = PROPERTY_SERVICE_TUT_PORI_APILTA+".swift.public_endpoint"; 042 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_SHOCK_GROUP_RANGE = PROPERTY_SERVICE_TUT_PORI_APILTA+".shock.group_range"; 043 private static final String PROPERTY_SERVICE_TUT_PORI_APILTA_SHOCK_TIME_GROUP_DIFFERENCE = PROPERTY_SERVICE_TUT_PORI_APILTA+".shock.group_time_difference"; 044 private int _alertRemoveThreshold = 5; 045 private long _alertValidityTime = 10000; 046 private String _container = null; 047 private String _credential = null; 048 private long _defaultExpirationTime = 900; //900 seconds, 15 minutes 049 private String _endpoint = null; 050 private String _identity = null; 051 private String _preferredRegion = null; 052 private String _provider = null; 053 private String _publicEndpoint = null; 054 private double _shockGroupRange = 0; 055 private long _shockGroupTimeDifference = 0; 056 057 @Override 058 public void initialize(Properties properties) throws IllegalArgumentException { 059 _container = properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_CONTAINER); 060 if(StringUtils.isBlank(_container)){ 061 throw new IllegalArgumentException("Bad "+PROPERTY_SERVICE_TUT_PORI_APILTA_CONTAINER); 062 } 063 _credential = properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_CREDENTIAL); 064 if(StringUtils.isBlank(_credential)){ 065 throw new IllegalArgumentException("Bad "+PROPERTY_SERVICE_TUT_PORI_APILTA_CREDENTIAL); 066 } 067 _endpoint = properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_ENDPOINT); 068 if(StringUtils.isBlank(_endpoint)){ 069 throw new IllegalArgumentException("Bad "+PROPERTY_SERVICE_TUT_PORI_APILTA_ENDPOINT); 070 } 071 _identity = properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_IDENTITY); 072 if(StringUtils.isBlank(_identity)){ 073 throw new IllegalArgumentException("Bad "+PROPERTY_SERVICE_TUT_PORI_APILTA_IDENTITY); 074 } 075 _preferredRegion = properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_PREFERRED_REGION, ""); //can be left blank on the .properties file 076 _provider = properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_PROVIDER); 077 if(StringUtils.isBlank(_provider)){ 078 throw new IllegalArgumentException("Bad "+PROPERTY_SERVICE_TUT_PORI_APILTA_PROVIDER); 079 } 080 _publicEndpoint = properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_PUBLIC_ENDPOINT); 081 if(StringUtils.isBlank(_publicEndpoint)){ 082 throw new IllegalArgumentException("Bad "+PROPERTY_SERVICE_TUT_PORI_APILTA_PUBLIC_ENDPOINT); 083 } 084 try{ 085 _defaultExpirationTime = Long.parseLong(properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_DEFAULT_EXPIRATION_TIME)); 086 _alertRemoveThreshold = Integer.parseInt(properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_ALERT_REMOVE_THRESHOLD)); 087 _alertValidityTime = Long.parseLong(properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_ALERT_VALIDITY_TIME)); 088 _shockGroupTimeDifference = Long.parseLong(properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_SHOCK_TIME_GROUP_DIFFERENCE)); 089 _shockGroupRange = Double.parseDouble(properties.getProperty(PROPERTY_SERVICE_TUT_PORI_APILTA_SHOCK_GROUP_RANGE)) / 1000; 090 } catch (NullPointerException | NumberFormatException ex) { 091 Logger.getLogger(getClass()).debug(ex, ex); 092 throw new IllegalArgumentException("Bad "+PROPERTY_SERVICE_TUT_PORI_APILTA_SHOCK_TIME_GROUP_DIFFERENCE+", "+PROPERTY_SERVICE_TUT_PORI_APILTA_DEFAULT_EXPIRATION_TIME+", "+PROPERTY_SERVICE_TUT_PORI_APILTA_ALERT_REMOVE_THRESHOLD+", "+PROPERTY_SERVICE_TUT_PORI_APILTA_SHOCK_GROUP_RANGE+" or "+PROPERTY_SERVICE_TUT_PORI_APILTA_ALERT_VALIDITY_TIME); 093 } 094 } 095 096 @Override 097 public String getPropertyFilePath() { 098 return ServiceInitializer.getConfigHandler().getPropertyFilePath()+"apilta.properties"; 099 } 100 101 /** 102 * @return the container 103 */ 104 public String getContainer() { 105 return _container; 106 } 107 108 /** 109 * @return the credential 110 */ 111 public String getCredential() { 112 return _credential; 113 } 114 115 /** 116 * @return the defaultExpirationTime 117 */ 118 public long getDefaultExpirationTime() { 119 return _defaultExpirationTime; 120 } 121 122 /** 123 * @return the endpoint 124 */ 125 public String getEndpoint() { 126 return _endpoint; 127 } 128 129 /** 130 * @return the identity 131 */ 132 public String getIdentity() { 133 return _identity; 134 } 135 136 /** 137 * @return the preferredRegion 138 */ 139 public String getPreferredRegion() { 140 return _preferredRegion; 141 } 142 143 /** 144 * @return the provider 145 */ 146 public String getProvider() { 147 return _provider; 148 } 149 150 /** 151 * @return the publicEndpoint 152 */ 153 public String getPublicEndpoint() { 154 return _publicEndpoint; 155 } 156 157 /** 158 * @return the default threshold until an alert is removed after negative reports have been removed 159 */ 160 public int getAlertRemoveThreshold() { 161 return _alertRemoveThreshold; 162 } 163 164 /** 165 * @return the default time a new alert is valid (in minutes) 166 */ 167 public long getAlertValidityTime() { 168 return _alertValidityTime; 169 } 170 171 /** 172 * @return the shockGroupTimeDifference 173 */ 174 public long getShockGroupTimeDifference() { 175 return _shockGroupTimeDifference; 176 } 177 178 /** 179 * @return the default range used for grouping shock measurements (in km) 180 */ 181 public double getShockGroupRange() { 182 return _shockGroupRange; 183 } 184}