Skip to content

Commit

Permalink
Merge pull request #35 from indigo-dc/spring-boot
Browse files Browse the repository at this point in the history
fix path issues + add daemon build
  • Loading branch information
bertl4398 authored Jul 1, 2016
2 parents f78c9d0 + 64508b2 commit 976c834
Show file tree
Hide file tree
Showing 39 changed files with 513 additions and 232 deletions.
10 changes: 7 additions & 3 deletions build_release_deb.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash

VERSION=0.1
NAME=cdmi-server

mvn clean package

mkdir -p debian/usr/lib/cdmi-server
cp target/cdmi-server-0.1-SNAPSHOT.jar debian/usr/lib/cdmi-server
mkdir -p debian/var/lib/$NAME/config/
cp config/application.yml debian/var/lib/$NAME/config/
cp target/$NAME-$VERSION-SNAPSHOT.jar debian/var/lib/$NAME/

dpkg --build debian

mv debian.deb cdmi-server-1.0.deb
mv debian.deb $NAME-$VERSION.deb
10 changes: 7 additions & 3 deletions build_release_rpm.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/bin/bash

VERSION=0.1
NAME=cdmi-server
TOPDIR=`pwd`/rpm

mvn clean package

cp target/cdmi-server-0.1-SNAPSHOT.jar $TOPDIR/SOURCES
cp target/$NAME-$VERSION-SNAPSHOT.jar $TOPDIR/SOURCES
cp config/application.yml $TOPDIR/SOURCES

rpmbuild --define "_topdir ${TOPDIR}" -ba $TOPDIR/SPECS/cdmi-server.spec
rpmbuild --define "_topdir ${TOPDIR}" -ba $TOPDIR/SPECS/$NAME.spec

cp ${TOPDIR}/RPMS/x86_64/cdmi-server-1.0-1.el7.centos.x86_64.rpm .
cp ${TOPDIR}/RPMS/x86_64/cdmi-server-0.1-1.x86_64.rpm .
#cp ${TOPDIR}/RPMS/x86_64/cdmi-server-1.0-1.el7.centos.x86_64.rpm .
20 changes: 20 additions & 0 deletions config/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
spring:
profiles:
active: filesystem

server:
port: 8888

rest:
user: restadmin
pass: restadmin
---
spring:
profiles: filesystem
cdmi:
data:
baseDirectory: /tmp/cdmi
objectIdPrefix: .cdmi_
qos:
backend:
type: dummy_filesystem
30 changes: 30 additions & 0 deletions debian/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

NAME=cdmi-server
VERSION=0.1
USER=cdmi

count=`egrep -c "^${USER}:" /etc/group`
if [ $count -eq 0 ]; then
echo "No ${USER} group found ... create group"
addgroup --system $USER
fi

/usr/bin/id -u $USER > /dev/null 2>&1
if [ $? -eq 1 ]; then
echo "No ${USER} user found .. create user"
adduser --system $USER --ingroup $USER
fi

if [ -f /var/lib/$NAME/$NAME-$VERSION-SNAPSHOT.jar ]; then
chmod +x /var/lib/$NAME/$NAME-$VERSION-SNAPSHOT.jar
fi

chown -R $USER:$USER /var/lib/$NAME/

if [ ! -L /etc/init.d/$NAME ]; then
ln -s /var/lib/$NAME/$NAME-$VERSION-SNAPSHOT.jar /etc/init.d/$NAME
fi

service $NAME start
update-rc.d $NAME defaults 99
11 changes: 11 additions & 0 deletions debian/etc/systemd/system/cdmi-server.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=cdmi-server
After=syslog.target

[Service]
User=cdmi
ExecStart=/var/lib/cdmi-server/cdmi-server-0.1-SNAPSHOT.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
11 changes: 11 additions & 0 deletions debian/etc/systemd/system/identity-harmonization.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=cdmi-server
After=syslog.target

[Service]
User=cdmi
ExecStart=/var/lib/cdmi-server/cdmi-server-0.1-SNAPSHOT.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
2 changes: 0 additions & 2 deletions debian/usr/bin/cdmi-server

This file was deleted.

5 changes: 1 addition & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@
<configuration>
<skipTests>false</skipTests>
<includes>
<include>edu.kit.scc.cdmi.filesystem.FileSystemTestSuite.java</include>
<include>edu.kit.scc.cdmi.rest.RestTestSuite.java</include>
<include>edu.kit.scc.TestSuite.java</include>
<include>edu.kit.scc.http.client.HttpTestSuite.java</include>
<include>edu.kit.scc.test.TestSuite.java</include>
</includes>
</configuration>
</plugin>
Expand Down
2 changes: 0 additions & 2 deletions rpm/SOURCES/cdmi-server

This file was deleted.

11 changes: 11 additions & 0 deletions rpm/SOURCES/cdmi-server.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=cdmi-server
After=syslog.target

[Service]
User=cdmi
ExecStart=/var/lib/cdmi-server/cdmi-server-0.1-SNAPSHOT.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
38 changes: 29 additions & 9 deletions rpm/SPECS/cdmi-server.spec
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
%define __jar_repack %{nil}
%define _tmppath %{_topdir}/tmp
%define buildroot %{_topdir}/hello-rpm-root
%define buildroot %{_topdir}/build-rpm-root

Name: cdmi-server
Version: 1.0
%define name cdmi-server
%define jarversion 0.1
%define user cdmi

Name: %{name}
Version: %{jarversion}
Release: 1%{?dist}
Summary: SNIA CDMI server reference implementation.

Expand All @@ -22,14 +26,30 @@ Standalone Spring Boot application version.
%build

%install
mkdir -p %{buildroot}/usr/local/bin
mkdir -p %{buildroot}/usr/lib/cdmi-server
cp %{_topdir}/SOURCES/cdmi-server %{buildroot}/usr/local/bin/cdmi-server
cp %{_topdir}/SOURCES/cdmi-server-0.1-SNAPSHOT.jar %{buildroot}/usr/lib/cdmi-server
mkdir -p %{buildroot}/var/lib/%{name}/config
mkdir -p %{buildroot}/etc/systemd/system
cp %{_topdir}/SOURCES/application.yml %{buildroot}/var/lib/%{name}/config
cp %{_topdir}/SOURCES/%{name}-%{jarversion}-SNAPSHOT.jar %{buildroot}/var/lib/%{name}
cp %{_topdir}/SOURCES/%{name}.service %{buildroot}/etc/systemd/system

%files
/usr/local/bin/cdmi-server
/usr/lib/cdmi-server/cdmi-server-0.1-SNAPSHOT.jar
/var/lib/%{name}/config/application.yml
/var/lib/%{name}/%{name}-%{jarversion}-SNAPSHOT.jar
/etc/systemd/system/%{name}.service

%changelog

%post
/usr/bin/id -u %{user} > /dev/null 2>&1
if [ $? -eq 1 ]; then
adduser --system --user-group %{user}
fi

if [ -f /var/lib/%{name}/%{name}-%{jarversion}-SNAPSHOT.jar ]; then
chmod +x /var/lib/%{name}/%{name}-%{jarversion}-SNAPSHOT.jar
fi

chown -R %{user}:%{user} /var/lib/%{name}

systemctl start %{name}.service
systemctl enable %{name}.service
1 change: 1 addition & 0 deletions src/main/java/edu/kit/scc/CdmiRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ public boolean verifyAuthorization(String authorizationHeader) {
String body = "token=" + encodedCredentials;
response = httpClient.makeHttpsPostRequest(clientId, clientSecret, body, tokenInfo);
if (response.statusCode == HttpStatus.OK.value()) {
log.debug("Token info {}", response.getResponseString());
// TODO set client ACLs
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/kit/scc/FilesystemBeanConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("filesystem")
@Profile({"filesystem", "test"})
public class FilesystemBeanConfiguration {

@Value("${cdmi.data.baseDirectory}")
Expand Down
44 changes: 20 additions & 24 deletions src/main/java/edu/kit/scc/FilesystemConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.snia.cdmiserver.model.Capability;
import org.snia.cdmiserver.model.CdmiObject;
import org.snia.cdmiserver.model.Container;
import org.snia.cdmiserver.model.Domain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
Expand All @@ -37,7 +36,7 @@
import javax.annotation.PreDestroy;

@Component
@Profile("filesystem")
@Profile({"filesystem", "test"})
public class FilesystemConfiguration {

private static final Logger log = LoggerFactory.getLogger(FilesystemConfiguration.class);
Expand All @@ -63,29 +62,37 @@ public class FilesystemConfiguration {
public void init() throws IOException {
log.debug("Set-up root container...");

CdmiObject rootObject = new CdmiObject();

Path path = Paths.get(baseDirectory);
if (!Files.exists(path)) {
Files.createDirectories(Paths.get(baseDirectory, "cdmi_objectid"));
Files.createDirectory(Paths.get(baseDirectory));
log.debug("root directory {} created", path.toString());
}
Container rootContainer = new Container("/", "/", rootObject.getObjectId());
rootContainer.setObjectId(rootObject.getObjectId());

cdmiObjectDao.createCdmiObject(rootContainer, baseDirectory);
path = Paths.get(baseDirectory, "cdmi_objectid");
if (!Files.exists(path)) {
Files.createDirectory(path);
log.debug("cdmi objectid directory {} created", path.toString());
}

path = Paths.get(baseDirectory, "cdmi_capabilities");
if (!Files.exists(path)) {
Files.createDirectory(Paths.get(baseDirectory, "cdmi_capabilities"));
log.debug("capabilities directory {} created", path.toString());
Files.createDirectory(path);
log.debug("cdmi objectid directory {} created", path.toString());
}

rootObject = cdmiObjectDao.getCdmiObjectByPath(baseDirectory);
CdmiObject rootObject = new CdmiObject();
Container rootContainer = new Container("/", "/", rootObject.getObjectId());
rootContainer.setObjectId(rootObject.getObjectId());

rootContainer = (Container) cdmiObjectDao.createCdmiObject(rootContainer, "/");
log.debug("root container created {}", rootContainer.toString());

rootObject = cdmiObjectDao.getCdmiObjectByPath("/");

Capability rootCapability = new Capability("cdmi_capabilities", "/", rootObject.getObjectId());
cdmiObjectDao.createCdmiObject(rootCapability,
Paths.get(baseDirectory, "cdmi_capabilities").toString());
rootCapability =
(Capability) cdmiObjectDao.createCdmiObject(rootCapability, "/cdmi_capabilities");
log.debug("root capability created {}", rootCapability.toString());

Capability containerCapability =
new Capability("container", "/cdmi_capabilities", rootCapability.getObjectId());
Expand All @@ -97,17 +104,6 @@ public void init() throws IOException {
capabilityDao.createByPath(Paths.get("cdmi_capabilities", "dataobject").toString(),
dataObjectCapability);

path = Paths.get(baseDirectory, "cdmi_domains");
if (!Files.exists(path)) {
Files.createDirectory(path);
log.debug("domain directory {} created", path.toString());
}
rootObject = cdmiObjectDao.getCdmiObjectByPath(baseDirectory);

Domain rootDomain = new Domain("cdmi_domains", "/", rootObject.getObjectId());

cdmiObjectDao.createCdmiObject(rootDomain, Paths.get(baseDirectory, "cdmi_domains").toString());

Capability defaultContainerCapability =
capabilityDao.findByPath(Paths.get("cdmi_capabilities", "container").toString());
log.debug(defaultContainerCapability.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
*/
public class CapabilityDaoImpl implements CapabilityDao {

private static final Logger LOG = LoggerFactory.getLogger(CapabilityDaoImpl.class);
private static final Logger log = LoggerFactory.getLogger(CapabilityDaoImpl.class);

private String baseDirectory;

Expand Down Expand Up @@ -80,52 +80,53 @@ public Capability findByObjectId(String objectId) {

@Override
public Capability findByPath(String path) {
return (Capability) cdmiObjectDao
.getCdmiObjectByPath(Paths.get(baseDirectory.trim(), path.trim()).toString());
return (Capability) cdmiObjectDao.getCdmiObjectByPath(path.trim());
}

@Override
public Capability createByPath(String path, Capability capabilityRequest) {
if (path == null) {
return null;
}

// TODO: only allow paths containing "cdmi_capabilities"

final Path capabilityPath = Paths.get(baseDirectory.trim(), path.trim());

try {
final Path capabilityPath = Paths.get(baseDirectory.trim(), path.trim());
// create the capability directory
Files.createDirectory(capabilityPath);
LOG.debug("create capability object {}", path.trim());
log.debug("create capability object {} {}", path.trim(), capabilityRequest.toString());
log.debug("create directory {}", capabilityPath.toString());
} catch (FileAlreadyExistsException ex) {
LOG.error(ex.getMessage());
return null;
log.error(ex.getMessage());
} catch (Exception ex) {
LOG.error(ex.getMessage());
log.error(ex.getMessage());
return null;
}

String objectName = capabilityPath.getFileName().toString();
String parentUri = Paths.get(path.trim()).getParent().toString();
String parentPath = capabilityPath.getParent().toString();
Path urlPath = Paths.get(path.trim());
Path parentPath = urlPath.getParent();
if (parentPath == null) {
return null;
}

// create the capability meta-data files
Capability parentCapability =
(Capability) cdmiObjectDao.getCdmiObjectByPath(parentPath.toString());

Capability capability = new Capability(objectName, parentUri, parentCapability.getObjectId());
Capability capability = new Capability(urlPath.getFileName().toString(), parentPath.toString(),
parentCapability.getObjectId());

if (parentCapability.getChildren() == null) {
parentCapability.setChildren(new JSONArray());
}

parentCapability.getChildren().put(capability.getObjectName());
String childrenRange = CdmiObject.getChildrenRange(parentCapability.getChildren());
parentCapability.setChildrenrange(childrenRange);

capability.setMetadata(capabilityRequest.getMetadata());
capability.setCapabilities(capabilityRequest.getCapabilities());

cdmiObjectDao.createCdmiObject(capability, capabilityPath.toString());
if (cdmiObjectDao.createCdmiObject(capability, urlPath.toString()) == null) {
return (Capability) cdmiObjectDao.deleteCdmiObjectByPath(urlPath.toString());
}
cdmiObjectDao.updateCdmiObject(parentCapability);

return capability;
}

}
Loading

0 comments on commit 976c834

Please sign in to comment.