|
1 | 1 | package api |
2 | 2 |
|
3 | 3 | import javax.inject.Inject |
4 | | - |
5 | | -import play.api.Logger |
| 4 | +import play.api.{Logger, Play} |
6 | 5 | import models.User |
7 | 6 | import play.api.Play._ |
8 | 7 | import play.api.libs.json.{JsValue, Json} |
9 | 8 | import services._ |
10 | 9 | import services.mongodb.MongoSalatPlugin |
| 10 | +import services.s3.S3ByteStorageService |
11 | 11 |
|
12 | 12 | import scala.collection.mutable |
13 | 13 |
|
@@ -35,6 +35,7 @@ class Status @Inject()(spaces: SpaceService, |
35 | 35 | "version" -> getVersionInfo, |
36 | 36 | "counts" -> getCounts(request.user), |
37 | 37 | "plugins" -> getPlugins(request.user), |
| 38 | + "storage" -> getStorage(request.user), |
38 | 39 | "extractors" -> Json.toJson(extractors.getExtractorNames(List.empty)))) |
39 | 40 | } |
40 | 41 |
|
@@ -138,6 +139,35 @@ class Status @Inject()(spaces: SpaceService, |
138 | 139 | Json.toJson(result.toMap[String, JsValue]) |
139 | 140 | } |
140 | 141 |
|
| 142 | + def getStorage(user: Option[User]): JsValue = { |
| 143 | + val config = Play.current.configuration |
| 144 | + val result = new mutable.HashMap[String, String]() |
| 145 | + |
| 146 | + ByteStorageService.storage.getClass.getName match { |
| 147 | + case "services.mongodb.MongoDBByteStorage" => { |
| 148 | + result.put("location", "mongo") |
| 149 | + } |
| 150 | + case "services.filesystem.DiskByteStorageService" => { |
| 151 | + result.put("location", "disk") |
| 152 | + if (Permission.checkServerAdmin(user)) { |
| 153 | + result.put("path", config.getString("clowder.diskStorage.path").getOrElse[String]("unknown")) |
| 154 | + } |
| 155 | + } |
| 156 | + case "services.s3.S3ByteStorageService" => { |
| 157 | + result.put("location", "s3") |
| 158 | + if (Permission.checkServerAdmin(user)) { |
| 159 | + result.put("endpoint", config.getString(S3ByteStorageService.ServiceEndpoint).getOrElse[String]("unknown")) |
| 160 | + result.put("region", config.getString(S3ByteStorageService.Region).getOrElse[String]("unknown")) |
| 161 | + result.put("bucket", config.getString(S3ByteStorageService.BucketName).getOrElse[String]("unknown")) |
| 162 | + } |
| 163 | + } |
| 164 | + case name => { |
| 165 | + result.put("location", name) |
| 166 | + } |
| 167 | + } |
| 168 | + Json.toJson(result.toMap[String, String]) |
| 169 | + } |
| 170 | + |
141 | 171 | def getCounts(user: Option[User]): JsValue = { |
142 | 172 | val counts = appConfig.getIndexCounts() |
143 | 173 | // TODO: Revisit this check as it is currently too slow |
|
0 commit comments