This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add web UI for mover and copy. (#927)
* merge the 'zeppelin' app.js to 'trunk'. * Change button style of rules (#747) * Add tooltip for action (#765) * Fix #741 Remove the usage of view * change button to phglyphicon, start and stop button combine into one * add tooltip * add tooltip for rules and actions * Change home.html (#786) * Fix #741 Remove the usage of view * change button to phglyphicon, start and stop button combine into one * add tooltip * add tooltip for rules and actions * change home.html * change about smart modal content * Add help for actions (#794) * #778 Add Rule format description on UI (#810) * Fix #741 Remove the usage of view * change button to phglyphicon, start and stop button combine into one * add tooltip * add tooltip for rules and actions * change home.html * change about smart modal content * add help for actions * #778 Add Rule format description on UI * #778 Add Rule format description on UI * #778 Add Rule format description on UI * #778 Add Rule format description on UI * Add SmartNotebook (#831) * Add SmartNotebook * Add SmartNotebook * Fix build bugs and web UI * change the home page. * remove 'zeppelin-web' from 'smart-zeppelin' default module. * Update the web UI "Smart Manager" to "Smart Storage Manager" * Add mover and copy view. * Merge trunk
- Loading branch information
zhiqiang
authored
Aug 15, 2017
1 parent
2cf2723
commit 8c23ce7
Showing
4 changed files
with
227 additions
and
10 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
smart-server/src/main/scala/org/smartdata/server/web/ActionService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.smartdata.server.web | ||
|
||
import java.util | ||
|
||
import scala.collection.JavaConverters._ | ||
import akka.http.scaladsl.server.Directives.{complete, path, pathPrefix, _} | ||
import akka.http.scaladsl.server.Route | ||
import akka.http.scaladsl.server.directives.ParameterDirectives.ParamMagnet | ||
import akka.stream.Materializer | ||
import com.google.gson.Gson | ||
import org.smartdata.actions.ActionRegistry | ||
import org.smartdata.model._ | ||
import org.smartdata.server.SmartEngine | ||
|
||
import scala.util.Random | ||
|
||
class ActionService(ssmServer: SmartEngine) extends BasicService { | ||
private val gson: Gson = new Gson() | ||
private val actions: util.Collection[ActionInfo] = new util.ArrayList[ActionInfo]() | ||
val builder = new ActionInfo.Builder() | ||
.setActionName("test") | ||
.setCreateTime(1024) | ||
.setFinished(true) | ||
.setFinishTime(2048) | ||
.setResult("this is result") | ||
.setLog("this is log") | ||
.setArgs(CmdletDescriptor.fromCmdletString("test -opt1 val1").getActionArgs(0)) | ||
.setProgress(0.5f) | ||
.setResult("objc[41272]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/bin/java (0x1075fd4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1076d94e0). One of the two will be used. Which one is undefined.") | ||
.setLog("objc[41272]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/bin/java (0x1075fd4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1076d94e0). One of the two will be used. Which one is undefined.") | ||
actions.add(builder.build()) | ||
|
||
private val actionTypes: util.Collection[ActionDescriptor] = new util.ArrayList[ActionDescriptor]() | ||
actionTypes.add(new ActionDescriptor("ls", "List files", "Comment", "Usage")) | ||
actionTypes.add(new ActionDescriptor("write", "Write files", "Comment", "Usage")) | ||
|
||
override protected def doRoute(implicit mat: Materializer): Route = | ||
pathPrefix("actions" / LongNumber) { actionId => | ||
path("detail") { | ||
complete(gson.toJson(actions.asScala.find(_.getActionId == actionId).get)) | ||
// complete(gson.toJson(ssmServer.getCommandExecutor.getActionInfo(actionId))) | ||
} | ||
} ~ | ||
path("cachedfiles") { | ||
val status = new util.ArrayList[CachedFileStatus]() | ||
status.add(new CachedFileStatus(1, "file1", 1023, 2048, 5)) | ||
status.add(new CachedFileStatus(2, "file2", 1023000, 2048000, 4)) | ||
complete(gson.toJson(status)) | ||
// complete(gson.toJson(ssmServer.getDBAdapter.getCachedFileStatus)) | ||
} ~ | ||
path("hotfiles") { | ||
// val tables = ssmServer.getStatesManager.getTablesInLast(Constants.ONE_HOUR_IN_MILLIS) | ||
// complete(gson.toJson(ssmServer.getDBAdapter.getHotFiles(tables, 20))) | ||
val status = new util.ArrayList[FileAccessInfo]() | ||
status.add(new FileAccessInfo(101L, "file1", 10)) | ||
status.add(new FileAccessInfo(102L, "file2", 20)) | ||
complete(gson.toJson(status)) | ||
} ~ | ||
path("actiontypes") { | ||
complete(gson.toJson(ActionRegistry.supportedActions())) | ||
} ~ | ||
path("actionlist") { | ||
complete(gson.toJson(actions)) | ||
// complete(gson.toJson(ssmServer.getCommandExecutor.listNewCreatedActions(20))) | ||
} ~ | ||
path("submitaction" / Segment) { actionType => | ||
post { | ||
parameters(ParamMagnet("args")) { args: String => | ||
val rule = java.net.URLDecoder.decode(args, "UTF-8") | ||
val action = new ActionInfo.Builder().setActionName(actionType) | ||
.setActionId(Math.abs(Random.nextInt())) | ||
.setArgs(CmdletDescriptor.fromCmdletString(actionType + " " + args).getActionArgs(0)) | ||
.setCreateTime(System.currentTimeMillis()) | ||
.setFinished(false) | ||
.setSuccessful(false).build() | ||
actions.add(action) | ||
try { | ||
// ssmServer.getCommandExecutor.submitCommand(actionType + " " + args) | ||
complete("Success") | ||
} catch { | ||
case e: Exception => failWith(e) | ||
} | ||
} | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
smart-server/src/main/scala/org/smartdata/server/web/RuleService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.smartdata.server.web | ||
|
||
import java.util | ||
|
||
import akka.http.scaladsl.server.Directives.{complete, path, _} | ||
import akka.http.scaladsl.server.Route | ||
import akka.stream.Materializer | ||
import com.google.gson.Gson | ||
import org.smartdata.model.CmdletState | ||
import org.smartdata.model.{CmdletInfo, RuleInfo} | ||
import org.smartdata.model.RuleState | ||
import org.smartdata.server.SmartEngine | ||
import org.smartdata.server.utils.JsonUtil | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.util.Random | ||
|
||
class RuleService(ssmServer: SmartEngine) extends BasicService { | ||
private val gson: Gson = new Gson() | ||
private val rules: util.Collection[RuleInfo] = new util.ArrayList[RuleInfo]() | ||
|
||
override protected def doRoute(implicit mat: Materializer): Route = pathPrefix("rules" / IntNumber) { ruleId => | ||
path("start") { | ||
post { | ||
try { | ||
// ssmServer.getRuleManager.activateRule(ruleId) | ||
rules.asScala.filter(_.getId == ruleId).foreach(_.setState(RuleState.ACTIVE)) | ||
complete("success") | ||
} catch { | ||
case e: Exception => failWith(e) | ||
} | ||
} | ||
} ~ | ||
path("stop") { | ||
delete { | ||
try { | ||
// ssmServer.getRuleManager.disableRule(ruleId, true) | ||
rules.asScala.filter(_.getId == ruleId).foreach(_.setState(RuleState.DISABLED)) | ||
complete("success") | ||
} catch { | ||
case e: Exception => failWith(e) | ||
} | ||
} | ||
} ~ | ||
path("detail") { | ||
try { | ||
complete(gson.toJson(rules.asScala.find(_.getId == ruleId).get)) | ||
// complete(gson.toJson(ssmServer.getRuleManager.getRuleInfo(ruleId))) | ||
} catch { | ||
case e: Exception => failWith(e) | ||
} | ||
} ~ | ||
path("errors") { | ||
complete("{\"time\" : \"0\", \"error\" : \"\"}") | ||
} ~ | ||
path("cmdlets") { | ||
val smap1 = new util.HashMap[String, String] | ||
smap1.put("_FILE_PATH_", "/testCacheFile") | ||
val cmdlet1 = new CmdletInfo(0, 1, | ||
CmdletState.PENDING, JsonUtil.toJsonString(smap1), 123123333l, 232444444l) | ||
val cmdlet2 = new CmdletInfo(1, 1, CmdletState.PENDING, | ||
JsonUtil.toJsonString(smap1), 123178333l, 232444994l) | ||
try { | ||
complete(gson.toJson(util.Arrays.asList(cmdlet1, cmdlet2))) | ||
// complete(gson.toJson(ssmServer.getCommandExecutor.listCommandsInfo(ruleId, null))) | ||
} catch { | ||
case e: Exception => failWith(e) | ||
} | ||
} | ||
} ~ | ||
path("rulelist") { | ||
try { | ||
complete(gson.toJson(rules)) | ||
// complete(gson.toJson(ssmServer.getRuleManager.listRulesInfo())) | ||
} catch { | ||
case e: Exception => failWith(e) | ||
} | ||
} ~ | ||
path("addrule") { | ||
post { | ||
entity(as[String]) { request => | ||
val rule = java.net.URLDecoder.decode(request, "UTF-8") | ||
System.out.println("Adding rule: " + rule) | ||
try { | ||
addRuleInfo(rule) | ||
// ssmServer.getRuleManager.submitRule(rule, RuleState.DISABLED) | ||
complete("Success") | ||
} catch { | ||
case e: Exception => failWith(e) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private def addRuleInfo(rule: String): RuleInfo = { | ||
val builder = RuleInfo.newBuilder | ||
builder.setRuleText(rule).setId(Math.abs(Random.nextInt())).setState(RuleState.DISABLED) | ||
val ruleInfo = builder.build | ||
rules.add(ruleInfo) | ||
ruleInfo | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters