Search in sources :

Example 36 with ItemBase

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;
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ItemBase(org.platformlayer.core.model.ItemBase) JAXBException(javax.xml.bind.JAXBException) JaxbHelper(org.platformlayer.xml.JaxbHelper)

Example 37 with ItemBase

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);
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsTarget(org.platformlayer.ops.OpsTarget) OpsException(org.platformlayer.ops.OpsException) PersistentInstance(org.platformlayer.instances.model.PersistentInstance) ItemBase(org.platformlayer.core.model.ItemBase) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Tag(org.platformlayer.core.model.Tag) InstanceBase(org.platformlayer.core.model.InstanceBase) Machine(org.platformlayer.ops.Machine) Handler(org.platformlayer.ops.Handler)

Example 38 with ItemBase

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));
    }
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase)

Example 39 with ItemBase

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;
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) ManagedSecretKey(org.platformlayer.ops.crypto.ManagedSecretKey) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 40 with ItemBase

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();
    }
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) DatabaseServer(org.platformlayer.ops.databases.DatabaseServer) DatabaseTarget(org.platformlayer.ops.databases.DatabaseTarget) OpsContext(org.platformlayer.ops.OpsContext) BindingScope(org.platformlayer.ops.BindingScope)

Aggregations

ItemBase (org.platformlayer.core.model.ItemBase)56 OpsException (org.platformlayer.ops.OpsException)20 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)14 RepositoryException (org.platformlayer.RepositoryException)11 OpsContext (org.platformlayer.ops.OpsContext)11 Tag (org.platformlayer.core.model.Tag)8 BindingScope (org.platformlayer.ops.BindingScope)7 Machine (org.platformlayer.ops.Machine)7 DatabaseServer (org.platformlayer.ops.databases.DatabaseServer)6 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)6 Produces (javax.ws.rs.Produces)5 List (java.util.List)4 GET (javax.ws.rs.GET)4 TagChanges (org.platformlayer.core.model.TagChanges)4 OpsTarget (org.platformlayer.ops.OpsTarget)4 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)4 JAXBException (javax.xml.bind.JAXBException)3 Filter (org.platformlayer.Filter)3 InetAddressChooser (org.platformlayer.InetAddressChooser)3 StateFilter (org.platformlayer.StateFilter)3