Search in sources :

Example 1 with MysqlServer

use of org.platformlayer.service.mysql.model.MysqlServer in project platformlayer by platformlayer.

the class MysqlServerBootstrap method handler.

@Handler
public void handler() throws OpsException {
    MysqlServer model = OpsContext.get().getInstance(MysqlServer.class);
    MysqlTarget mysql = new MysqlTarget("localhost", "root", model.rootPassword);
    if (!mysql.canLogin()) {
        mysql = new MysqlTarget("localhost", "root", MysqlServerController.DEFAULT_BOOTSTRAP_PASSWORD);
        // Clean up the users table
        mysql.execute("delete from mysql.user where user='';");
        mysql.execute("update mysql.user set host='%' where user='root' and host='localhost';");
        mysql.execute("delete from mysql.user where user='root' and host<>'%';");
        mysql.execute("flush privileges;");
        mysql.changePassword(model.rootPassword);
    }
}
Also used : MysqlServer(org.platformlayer.service.mysql.model.MysqlServer) Handler(org.platformlayer.ops.Handler)

Example 2 with MysqlServer

use of org.platformlayer.service.mysql.model.MysqlServer in project platformlayer by platformlayer.

the class MysqlConnection method doRecurseOperation.

@Override
public void doRecurseOperation() throws OpsException {
    MysqlServer mysqlServer = platformLayerHelpers.getItem(key, MysqlServer.class);
    String username = this.username;
    if (username == null) {
        username = "root";
        password = mysqlServer.rootPassword;
    }
    Machine machine = instanceHelpers.getMachine(mysqlServer);
    String address = machine.getNetworkPoint().getBestAddress(NetworkPoint.forTargetInContext());
    MysqlTarget mysql = new MysqlTarget(address, username, password);
    BindingScope scope = BindingScope.push(mysql);
    try {
        OpsContext opsContext = OpsContext.get();
        OperationRecursor.doRecurseChildren(opsContext, this);
    } finally {
        scope.pop();
    }
}
Also used : MysqlTarget(org.platformlayer.service.mysql.ops.MysqlTarget) OpsContext(org.platformlayer.ops.OpsContext) MysqlServer(org.platformlayer.service.mysql.model.MysqlServer) Machine(org.platformlayer.ops.Machine) BindingScope(org.platformlayer.ops.BindingScope)

Example 3 with MysqlServer

use of org.platformlayer.service.mysql.model.MysqlServer in project platformlayer by platformlayer.

the class MysqlProvider method beforeCreateItem.

@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
    super.beforeCreateItem(item);
    // TODO: This doesn't feel like the right place for this
    if (item instanceof MysqlServer) {
        MysqlServer mysqlServer = (MysqlServer) item;
        Passwords passwords = new Passwords();
        if (Secret.isNullOrEmpty(mysqlServer.rootPassword)) {
            mysqlServer.rootPassword = passwords.generateRandomPassword(12);
        }
    }
}
Also used : Passwords(org.platformlayer.ops.crypto.Passwords) MysqlServer(org.platformlayer.service.mysql.model.MysqlServer)

Example 4 with MysqlServer

use of org.platformlayer.service.mysql.model.MysqlServer in project platformlayer by platformlayer.

the class MysqlServerController method addChildren.

@Override
protected void addChildren() throws OpsException {
    MysqlServer model = OpsContext.get().getInstance(MysqlServer.class);
    InstanceBuilder instance = InstanceBuilder.build(model.dnsName, this, model.getTags());
    // TODO: Memory _really_ needs to be configurable here!
    instance.publicPorts.add(3306);
    instance.minimumMemoryMb = 2048;
    instance.hostPolicy.allowRunInContainer = true;
    addChild(instance);
    {
        PackageDependency serverPackage = instance.addChild(PackageDependency.build("mysql-server"));
        // mysql-server-5.1 mysql-server/root_password_again password
        // mysql-server-5.1 mysql-server/root_password password
        // mysql-server-5.1 mysql-server-5.1/start_on_boot boolean true
        // mysql-server-5.1 mysql-server-5.1/postrm_remove_databases boolean false
        // mysql-server-5.1 mysql-server/error_setting_password error
        // mysql-server-5.1 mysql-server-5.1/nis_warning note
        // mysql-server-5.1 mysql-server-5.1/really_downgrade boolean false
        // mysql-server-5.1 mysql-server/password_mismatch error
        // mysql-server-5.1 mysql-server/no_upgrade_when_using_ndb error
        // We need to install with a default password, which we then change
        String plaintextPassword = DEFAULT_BOOTSTRAP_PASSWORD.plaintext();
        serverPackage.addConfiguration("mysql-server-5.1", "mysql-server/root_password", "password", plaintextPassword);
        serverPackage.addConfiguration("mysql-server-5.1", "mysql-server/root_password_again", "password", plaintextPassword);
    }
    // TODO: Is there a window of vulnerability when first booting a machine?
    // Do we need to secure it so that mysql doesn't listen remotely initially (or isn't running)?
    // Maybe use mysql-server-5.1 mysql-server-5.1/start_on_boot boolean true
    instance.addChild(PackageDependency.build("mysql-client"));
    instance.addChild(MysqlServerBootstrap.build());
    instance.addChild(SimpleFile.build(getClass(), new File("/etc/mysql/conf.d/bind_all.cnf")));
    instance.addChild(SimpleFile.build(getClass(), new File("/etc/mysql/conf.d/skip_name_resolve.cnf")));
    // Collectd not restarting correctly (doesn't appear to be hostname problems??)
    // instance.addChild(CollectdCollector.build());
    {
        PublicEndpoint endpoint = injected(PublicEndpoint.class);
        // endpoint.network = null;
        endpoint.publicPort = 3306;
        endpoint.backendPort = 3306;
        endpoint.dnsName = model.dnsName;
        endpoint.tagItem = model.getKey();
        endpoint.parentItem = model.getKey();
        instance.addChild(endpoint);
    }
    instance.addChild(ManagedService.build("mysql"));
}
Also used : PackageDependency(org.platformlayer.ops.packages.PackageDependency) PublicEndpoint(org.platformlayer.ops.networks.PublicEndpoint) File(java.io.File) SimpleFile(org.platformlayer.ops.filesystem.SimpleFile) MysqlServer(org.platformlayer.service.mysql.model.MysqlServer) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Aggregations

MysqlServer (org.platformlayer.service.mysql.model.MysqlServer)4 File (java.io.File)1 BindingScope (org.platformlayer.ops.BindingScope)1 Handler (org.platformlayer.ops.Handler)1 Machine (org.platformlayer.ops.Machine)1 OpsContext (org.platformlayer.ops.OpsContext)1 Passwords (org.platformlayer.ops.crypto.Passwords)1 SimpleFile (org.platformlayer.ops.filesystem.SimpleFile)1 InstanceBuilder (org.platformlayer.ops.instances.InstanceBuilder)1 PublicEndpoint (org.platformlayer.ops.networks.PublicEndpoint)1 PackageDependency (org.platformlayer.ops.packages.PackageDependency)1 MysqlTarget (org.platformlayer.service.mysql.ops.MysqlTarget)1