Skip to content

Commit

Permalink
Merge pull request #14 from takipi/develop
Browse files Browse the repository at this point in the history
develop merge
  • Loading branch information
chook authored Jan 15, 2017
2 parents 42de1b1 + 4579d21 commit fab33a1
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 3 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/takipi/oss/storage/TakipiStorageMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.takipi.oss.storage.resources.diag.PingStorageResource;
import com.takipi.oss.storage.resources.diag.StatusStorageResource;
import com.takipi.oss.storage.resources.diag.TreeStorageResource;
import com.takipi.oss.storage.resources.diag.VersionStorageResource;
import com.takipi.oss.storage.resources.fs.BinaryStorageResource;
import com.takipi.oss.storage.resources.fs.JsonMultiDeleteStorageResource;
import com.takipi.oss.storage.resources.fs.JsonMultiFetchStorageResource;
Expand Down Expand Up @@ -50,6 +51,7 @@ public void run(TakipiStorageConfiguration configuration, Environment environmen
environment.jersey().register(new JsonSimpleSearchStorageResource(configuration));

environment.jersey().register(new PingStorageResource());
environment.jersey().register(new VersionStorageResource());
environment.jersey().register(new TreeStorageResource(configuration));
environment.jersey().register(new StatusStorageResource(configuration));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class MachineStatus
private long namersSizeBytes;
private long sourceCodeCount;
private long sourceCodeSizeBytes;
private long cerebroCount;
private long cerebroSizeBytes;
private long freeSpaceLeftBytes;
private String machineName;
private String pid;
Expand All @@ -19,6 +21,7 @@ public class MachineStatus
private long usedRamBytes;
private long heapSizeBytes;
private long permGenSizeBytes;
private String version;

public void setHitsCount(long hitsCount) {
this.hitsCount = hitsCount;
Expand Down Expand Up @@ -68,6 +71,22 @@ public long getSourceCodeSizeBytes() {
return sourceCodeSizeBytes;
}

public void setCerebroCount(long cerebroCount) {
this.cerebroCount = cerebroCount;
}

public long getCerebroCount() {
return cerebroCount;
}

public void setCerebroSizeBytes(long cerebroSizeBytes) {
this.cerebroSizeBytes = cerebroSizeBytes;
}

public long getCerebroSizeBytes() {
return cerebroSizeBytes;
}

public void setFreeSpaceLeftBytes(long freeSpaceLeftBytes) {
this.freeSpaceLeftBytes = freeSpaceLeftBytes;
}
Expand Down Expand Up @@ -155,4 +174,12 @@ public void setPermGenSizeBytes(long permGenSizeBytes) {
public long getPermGenSizeBytes() {
return permGenSizeBytes;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/takipi/oss/storage/helper/StatusUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class StatusUtil {
private static String processName;
private static String processId;
private static String machineName;
private static String machineVersion;

public static String getMachineName() {
if (Strings.isNullOrEmpty(machineName)) {
Expand All @@ -25,6 +26,21 @@ public static String getMachineName() {
return machineName;
}

public static String getMachineVersion() {
if (Strings.isNullOrEmpty(machineVersion)) {
try {
machineVersion = StatusUtil.class.getPackage().getImplementationVersion();
}
catch (Exception e) { }

if (Strings.isNullOrEmpty(machineVersion)) {
machineVersion = "N/A";
}
}

return machineVersion;
}

public static String getProcessName() {
if (Strings.isNullOrEmpty(processName)) {
RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class StatusStorageResource {
private static final String sourceCodesSizeName = "sources size";
private static final String sourceCodesCountName = "sources count";
private static final String sourceCodeDirectoryName = "source-code";
private static final String cerebroSizeName = "cerebro size";
private static final String cerebroCountName = "cerebro count";
private static final String cerebroDirectoryName = "cerebro";

protected final String folderPath;

Expand Down Expand Up @@ -67,6 +70,8 @@ private void collectDataInfo(MachineStatus machineStatus) {
machineStatus.setNamersCount(mappedData.get(namersCountName));
machineStatus.setSourceCodeSizeBytes(mappedData.get(sourceCodesSizeName));
machineStatus.setSourceCodeCount(mappedData.get(sourceCodesCountName));
machineStatus.setCerebroSizeBytes(mappedData.get(cerebroSizeName));
machineStatus.setCerebroCount(mappedData.get(cerebroCountName));
machineStatus.setFreeSpaceLeftBytes(directory.getFreeSpace());
}

Expand Down Expand Up @@ -108,7 +113,11 @@ private void directoryHandler(Map<String, Long> map, File directory) {
case sourceCodeDirectoryName : {
handleSpecialDirectory(directory, sourceCodesSizeName, sourceCodesCountName, map);
break;
}
}
case cerebroDirectoryName: {
handleSpecialDirectory(directory, cerebroSizeName, cerebroCountName, map);
break;
}
default : {
traverseTreeForData(directory, map);
}
Expand Down Expand Up @@ -151,6 +160,8 @@ private Map<String, Long> initializeMapForData() {
result.put(namersCountName, 0l);
result.put(sourceCodesSizeName, 0l);
result.put(sourceCodesCountName, 0l);
result.put(cerebroSizeName, 0l);
result.put(cerebroCountName, 0l);

return result;
}
Expand All @@ -166,5 +177,6 @@ private void collectMachineInfo(MachineStatus machineStatus) {
machineStatus.setUsedRamBytes(StatusUtil.getUsedRamInBytes());
machineStatus.setHeapSizeBytes(StatusUtil.getHeapSizeInBytes());
machineStatus.setPermGenSizeBytes(StatusUtil.getPermGenSizeInBytes());
machineStatus.setVersion(StatusUtil.getMachineVersion());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.takipi.oss.storage.resources.diag;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codahale.metrics.annotation.Timed;
import com.takipi.oss.storage.helper.StatusUtil;

@Path("/storage/v1/diag/version")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public class VersionStorageResource {
private static final Logger logger = LoggerFactory.getLogger(VersionStorageResource.class);

@GET
@Timed
public Response get() {
try {
String implVersion = StatusUtil.getMachineVersion();

return Response.ok(implVersion).build();
} catch (Exception e) {
logger.error("Could not reply to version request", e);
return Response.serverError().entity("Could not reply to version request").build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.takipi.oss.storage.fs.Record;
import com.takipi.oss.storage.resources.fs.base.HashFileSystemStorageResource;

@Path("/storage/v1/binary/{serviceId}/{type}/{key}")
@Path("/storage/v1/binary/{serviceId}/{type}/{key:.+}")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public class BinaryStorageResource extends HashFileSystemStorageResource {
Expand Down Expand Up @@ -117,7 +117,9 @@ public Response delete(@PathParam("serviceId") @DefaultValue("") String serviceI
protected Response internalGet(Record record) throws IOException {
InputStream is = fs.get(record);

return Response.ok(is).build();
long size = fs.size(record);

return Response.ok(is).header(HttpHeaders.CONTENT_LENGTH, size).build();
}

protected Response internalHead(Record record) throws IOException {
Expand Down

0 comments on commit fab33a1

Please sign in to comment.