Search in sources :

Example 1 with GitService

use of org.platformlayer.service.git.model.GitService in project platformlayer by platformlayer.

the class GitServerAssignment method handler.

@Handler
public void handler(GitRepository model) throws Exception {
    PlatformLayerKey assignedTo = Tag.ASSIGNED_TO.findUnique(model.getTags());
    if (OpsContext.isConfigure()) {
        if (assignedTo == null) {
            List<GitService> gitServices = platformLayer.listItems(GitService.class);
            if (gitServices.size() == 0) {
                throw new OpsException("No git service found");
            }
            GitService gitService = RandomChooser.chooseRandom(gitServices);
            if (gitService == null) {
                throw new IllegalStateException();
            }
            assignedTo = gitService.getKey();
            platformLayer.addTag(model.getKey(), Tag.ASSIGNED_TO.build(assignedTo));
        }
    }
    GitService gitService = null;
    if (assignedTo != null) {
        gitService = platformLayer.getItem(assignedTo, GitService.class);
    }
    if (OpsContext.isDelete()) {
        if (gitService == null) {
            log.info("Deleting, but not assigned to a server; nothing to do");
            getRecursionState().setPreventRecursion(true);
            return;
        }
    }
    if (gitService == null) {
        throw new OpsException("No git servers found");
    }
    if (gitService.getState() != ManagedItemState.ACTIVE) {
        throw new OpsException("Server not yet active: " + gitService);
    }
    Machine machine = instances.findMachine(gitService);
    if (machine == null) {
        throw new OpsException("Server machine not found:" + gitService);
    }
    SshKey sshKey = service.getSshKey();
    OpsTarget target = machine.getTarget(sshKey);
    getRecursionState().pushChildScope(OpsTarget.class, target);
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsException(org.platformlayer.ops.OpsException) OpsTarget(org.platformlayer.ops.OpsTarget) GitService(org.platformlayer.service.git.model.GitService) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Machine(org.platformlayer.ops.Machine) Handler(org.platformlayer.ops.Handler)

Example 2 with GitService

use of org.platformlayer.service.git.model.GitService in project platformlayer by platformlayer.

the class GitServerController method getLdapDomain.

LdapDomain getLdapDomain() throws OpsException {
    if (ldapDomain == null) {
        GitService model = OpsContext.get().getInstance(GitService.class);
        LdapDN ldapGroup = LdapDN.parseLdifEncoded(model.ldapGroup);
        LdapDomain best = null;
        for (LdapDomain candidate : platformLayer.listItems(LdapDomain.class)) {
            switch(candidate.getState()) {
                case DELETE_REQUESTED:
                case DELETED:
                    continue;
            }
            LdapDN organizationName = LdapDN.fromDomainName(candidate.organizationName);
            if (!organizationName.isParentOf(ldapGroup)) {
                log.info("LdapDomain does not match: " + organizationName + " vs " + ldapGroup);
                continue;
            }
            log.info("Found matching LdapDomain: " + organizationName + " vs " + ldapGroup);
            if (best == null) {
                best = candidate;
                continue;
            }
            throw new UnsupportedOperationException("Selecting between matching LDAP domains not yet implemented");
        }
        if (best == null) {
            throw new IllegalStateException("Cannot find LDAP domain: " + model.ldapGroup);
        }
        ldapDomain = best;
    }
    return ldapDomain;
}
Also used : LdapDomain(org.platformlayer.service.openldap.model.LdapDomain) GitService(org.platformlayer.service.git.model.GitService) LdapDN(org.platformlayer.ops.ldap.LdapDN)

Example 3 with GitService

use of org.platformlayer.service.git.model.GitService in project platformlayer by platformlayer.

the class ITGitService method testCreateAndDeleteItem.

@Test
public void testCreateAndDeleteItem() throws Exception {
    OpenLdapTestHelpers openLdap = new OpenLdapTestHelpers(getContext());
    LdapService ldapService = openLdap.createLdapServer();
    openFirewall(ldapService, LdapServiceController.PORT);
    String organizationName = "test.platformlayer.org";
    LdapDomain ldapDomain = openLdap.createLdapDomain(ldapService, organizationName);
    String id = "git" + random.randomAlphanumericString(8);
    GitService service = new GitService();
    service.dnsName = id + ".test.platformlayer.org";
    service.ldapGroup = "ou=Git Users,dc=test,dc=platformlayer,dc=org";
    service = putItem(id, service);
    service = waitForHealthy(service);
    InetSocketAddress socketAddress = getUniqueEndpoint(service);
    Assert.assertFalse(isPortOpen(socketAddress));
    openFirewall(service, GitServerController.PORT);
    Assert.assertTrue(isPortOpen(socketAddress));
    String repoId = "repo" + id;
    GitRepository repo = new GitRepository();
    repo.name = repoId;
    repo = putItem(repoId, repo);
    repo = waitForHealthy(repo);
    // TODO: Make endpoint http://<ip>:<port>/<path>...
    String url = "http://" + socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort() + "/git/" + repoId;
    String username = null;
    String password = null;
    testGitRepo(url, username, password);
}
Also used : GitRepository(org.platformlayer.service.git.model.GitRepository) LdapDomain(org.platformlayer.service.openldap.model.LdapDomain) InetSocketAddress(java.net.InetSocketAddress) GitService(org.platformlayer.service.git.model.GitService) OpenLdapTestHelpers(org.platformlayer.service.openldap.tests.OpenLdapTestHelpers) LdapService(org.platformlayer.service.openldap.model.LdapService) Test(org.testng.annotations.Test) PlatformLayerApiTest(org.platformlayer.tests.PlatformLayerApiTest)

Example 4 with GitService

use of org.platformlayer.service.git.model.GitService in project platformlayer by platformlayer.

the class GitServerController method getLdapService.

LdapService getLdapService() throws OpsException {
    if (ldapService == null) {
        GitService model = OpsContext.get().getInstance(GitService.class);
        // String ldapGroup = model.ldapGroup;
        LdapService best = null;
        for (LdapService candidate : platformLayer.listItems(LdapService.class)) {
            switch(candidate.getState()) {
                case DELETE_REQUESTED:
                case DELETED:
                    continue;
            }
            // TODO: How to match?
            if (best == null) {
                best = candidate;
                continue;
            }
            throw new UnsupportedOperationException("Selecting between LDAP services not yet implemented");
        }
        if (best == null) {
            throw new IllegalStateException("Cannot find LDAP service: " + model.ldapGroup);
        }
        ldapService = best;
    }
    return ldapService;
}
Also used : GitService(org.platformlayer.service.git.model.GitService) LdapService(org.platformlayer.service.openldap.model.LdapService)

Example 5 with GitService

use of org.platformlayer.service.git.model.GitService in project platformlayer by platformlayer.

the class GitServerController method addChildren.

@Override
protected void addChildren() throws OpsException {
    GitService model = OpsContext.get().getInstance(GitService.class);
    InstanceBuilder vm = InstanceBuilder.build(model.dnsName, this, model.getTags());
    addChild(vm);
    vm.addChild(PackageDependency.build("apache2"));
    // Provides /usr/lib/git-core/git-http-backend
    vm.addChild(PackageDependency.build("git"));
    vm.addChild(ManagedDirectory.build(new File("/var/git"), "0755"));
    vm.addChild(ApacheModule.build("authnz_ldap"));
    vm.addChild(ApacheModule.build("ldap"));
    File apache2ConfDir = new File("/etc/apache2");
    vm.addChild(TemplatedFile.build(this, new File(apache2ConfDir, "conf.d/git")));
    vm.addChild(ManagedService.build("apache2"));
    vm.addChild(MetricsInstance.class);
    {
        PublicEndpoint endpoint = injected(PublicEndpoint.class);
        // endpoint.network = null;
        endpoint.publicPort = PORT;
        endpoint.backendPort = PORT;
        endpoint.dnsName = model.dnsName;
        endpoint.tagItem = model.getKey();
        endpoint.parentItem = model.getKey();
        vm.addChild(endpoint);
    }
}
Also used : GitService(org.platformlayer.service.git.model.GitService) PublicEndpoint(org.platformlayer.ops.networks.PublicEndpoint) TemplatedFile(org.platformlayer.ops.filesystem.TemplatedFile) File(java.io.File) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Aggregations

GitService (org.platformlayer.service.git.model.GitService)5 LdapDomain (org.platformlayer.service.openldap.model.LdapDomain)2 LdapService (org.platformlayer.service.openldap.model.LdapService)2 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)1 Handler (org.platformlayer.ops.Handler)1 Machine (org.platformlayer.ops.Machine)1 OpsException (org.platformlayer.ops.OpsException)1 OpsTarget (org.platformlayer.ops.OpsTarget)1 TemplatedFile (org.platformlayer.ops.filesystem.TemplatedFile)1 SshKey (org.platformlayer.ops.helpers.SshKey)1 InstanceBuilder (org.platformlayer.ops.instances.InstanceBuilder)1 LdapDN (org.platformlayer.ops.ldap.LdapDN)1 PublicEndpoint (org.platformlayer.ops.networks.PublicEndpoint)1 GitRepository (org.platformlayer.service.git.model.GitRepository)1 OpenLdapTestHelpers (org.platformlayer.service.openldap.tests.OpenLdapTestHelpers)1 PlatformLayerApiTest (org.platformlayer.tests.PlatformLayerApiTest)1 Test (org.testng.annotations.Test)1