Last active
August 29, 2015 14:13
-
-
Save songyunlu/804d83816e109bf7a17b to your computer and use it in GitHub Desktop.
Spring Cloud Config CassandraEnvironmentRepository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CassandraEnvironmentRepository implements EnvironmentRepository { | |
private static final Logger logger = Logger.getLogger(CassandraEnvironmentRepository.class); | |
@Autowired | |
private PropertiesRepository propertiesRepository; | |
@Override | |
public Environment findOne(final String application, final String profile, final String label) { | |
Environment result = new Environment(profile, label); | |
try { | |
final ConfigRepo configRepo = this.propertiesRepository.findById(application,profile,label); | |
if (configRepo != null) { | |
final Properties properties = this.loadProperties(Bytes.fromHexString(configRepo.getData()).array()); | |
if (properties != null) { | |
result.add(new PropertySource(profile, properties)); | |
} | |
} | |
} catch (final Exception e) { | |
CassandraEnvironmentRepository.logger.warn("Fail to fetch data from cassandra", e); | |
} | |
return result; | |
} | |
private Properties loadProperties(byte [] data) throws IOException { | |
Properties properties = new Properties(); | |
properties.load(new StringReader(new String(data))); | |
return properties; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment