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);
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations