use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method serialize.
byte[] serialize(ItemBase item, CryptoKey itemSecret) {
// Remove fields that are stored in other columns
// TODO: Is this the best way to do this?
// We use JAXB to avoid requiring everything to implement Serializable
ItemBase mutableItem = CloneHelpers.cloneViaJaxb(item);
mutableItem.tags = null;
mutableItem.key = null;
mutableItem.version = 0;
mutableItem.state = null;
JaxbHelper jaxbHelper = JaxbHelper.get(item.getClass());
StringWriter writer = new StringWriter();
try {
Marshaller marshaller = jaxbHelper.createMarshaller();
// OpsSecretEncryptionStrategy strategy = new OpsSecretEncryptionStrategy(itemSecret);
// strategy.setAdapter(marshaller);
marshaller.marshal(mutableItem, writer);
} catch (JAXBException e) {
throw new IllegalArgumentException("Could not serialize data", e);
}
String xml = writer.toString();
byte[] ciphertext = FathomdbCrypto.encrypt(itemSecret, Utf8.getBytes(xml));
return ciphertext;
}
use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class InstanceBuilder method doOperation.
@Handler
public void doOperation() throws OpsException, IOException {
ItemBase item = ops.getInstance(ItemBase.class);
Tag parentTag = Tag.buildParentTag(item.getKey());
PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();
persistentInstanceTemplate.getTags().add(parentTag);
// Set during doOperation
Machine machine = null;
PersistentInstance persistentInstance = null;
InstanceBase instance = null;
OpsTarget target = null;
persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);
if (persistentInstance != null) {
// We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
// TODO: Should we always use the instance id??
instance = instances.findInstance(persistentInstance);
if (instance == null && !OpsContext.isDelete()) {
// A machine has not (yet) been assigned
throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
}
}
if (instance != null) {
machine = cloudHelpers.toMachine(instance);
}
if (addTagToManaged && !OpsContext.isDelete()) {
// Add tag with instance id to persistent instance (very helpful for
// DNS service!)
PlatformLayerKey machineKey = machine.getKey();
platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
}
SshKey sshKey = service.getSshKey();
if (machine != null) {
if (OpsContext.isDelete()) {
target = null;
machine = null;
} else {
target = machine.getTarget(sshKey);
}
}
RecursionState recursion = getRecursionState();
if (OpsContext.isDelete() && machine == null) {
// Don't recurse into no machine :-)
recursion.setPreventRecursion(true);
}
recursion.pushChildScope(Machine.class, machine);
recursion.pushChildScope(PersistentInstance.class, persistentInstance);
recursion.pushChildScope(InstanceBase.class, instance);
recursion.pushChildScope(OpsTarget.class, target);
}
use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class InstanceBuilder method addChildren.
@Override
protected void addChildren() throws OpsException {
addChild(InstanceBootstrap.class);
addChild(DnsResolver.class);
String hostname = dnsName;
if (Strings.isNullOrEmpty(hostname)) {
// We always want to set a valid hostname
ItemBase item = ops.getInstance(ItemBase.class);
hostname = item.getId();
}
if (hostname != null) {
addChild(ConfigureHostname.build(hostname));
}
}
use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class StandardTemplateData method findCaKey.
public ManagedSecretKey findCaKey() throws OpsException {
PlatformLayerKey caPath = getCaPath();
if (caPath == null) {
return null;
}
ItemBase sslKeyItem = (ItemBase) platformLayer.getItem(caPath);
ManagedSecretKey key = providers.toInterface(sslKeyItem, ManagedSecretKey.class);
return key;
}
use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class DatabaseConnection method doRecurseOperation.
@Override
public void doRecurseOperation() throws OpsException {
ItemBase server = platformLayer.getItem(serverKey);
DatabaseServer database = providers.toInterface(server, DatabaseServer.class);
String username = this.username;
if (username == null) {
username = database.getRootUsername();
}
if (username.equals("postgres") && password == null) {
password = database.getRootPassword();
}
DatabaseTarget dbTarget = database.buildDatabaseTarget(username, password, databaseName);
BindingScope scope = BindingScope.push(dbTarget);
try {
OpsContext opsContext = OpsContext.get();
OperationRecursor.doRecurseChildren(opsContext, this);
} finally {
scope.pop();
}
}
Aggregations