svnno****@sourc*****
svnno****@sourc*****
2010年 1月 8日 (金) 22:08:53 JST
Revision: 84 http://sourceforge.jp/projects/ngms/svn/view?view=rev&revision=84 Author: osiire Date: 2010-01-08 22:08:53 +0900 (Fri, 08 Jan 2010) Log Message: ----------- [NGMS] Add README. [NMShell] add bin, share directories for initial data file structures. Modified Paths: -------------- trunk/source/NMShell/src/info/ngms/commands/ls.scala trunk/source/NMShell/src/info/ngms/nmshell/Main.scala trunk/source/NMShell/src/info/ngms/nmshell/NMShellEnvironment.scala trunk/source/NMTree/src/info/ngms/nmtree/NMDescription.scala trunk/source/NMTree/src/info/ngms/nmtree/NMFileSystemTree.scala trunk/source/NMTree/src/info/ngms/nmtree/NMTree.scala trunk/source/build.xml Added Paths: ----------- trunk/source/NMShell/src/info/ngms/commands/exit.scala trunk/source/NMShell/src/info/ngms/nmshell/NMShellConfigFile.scala trunk/source/NMShell/src/info/ngms/nmshell/NMShellPipe.scala trunk/source/NMTree/src/info/ngms/nmtree/NMTreeImplementations.scala trunk/source/README.txt trunk/source/bin/ trunk/source/bin/ngms trunk/source/bin/ngms.bat trunk/source/share/ trunk/source/share/ngms/ trunk/source/share/ngms/data/ trunk/source/share/ngms/data/config/ trunk/source/share/ngms/data/config/group trunk/source/share/ngms/data/config/user trunk/source/share/ngms/data/data/ trunk/source/share/ngms/data/tmp/ trunk/source/share/ngms/extends/ trunk/source/share/ngms/ngms.conf Removed Paths: ------------- trunk/source/ngms.bat trunk/source/ngms.sh Added: trunk/source/NMShell/src/info/ngms/commands/exit.scala =================================================================== --- trunk/source/NMShell/src/info/ngms/commands/exit.scala (rev 0) +++ trunk/source/NMShell/src/info/ngms/commands/exit.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1,33 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.commands + +import info.ngms.nmshell.NMCommand +import info.ngms.nmshell.NMCommandContext +import info.ngms.nmshell.NMCommandStream +import info.ngms.nmshell.NMCommandStreamKind +import info.ngms.nmshell.NMCommandParameterInfo +import info.ngms.nmshell.NMRawStream +import info.ngms.nmshell.RawStream +import info.ngms.nmtree.NMTreeElements + +class exit extends NMCommand { + val name = "exit" + + def parseOption( args : Array[String] ) : Unit = { + } + + def parameters : List[ NMCommandParameterInfo ] = { + Nil + } + + def doWork( env : NMCommandContext ) : Unit = { + // terminate + System.exit(0) + } + + def inputStreamKind = RawStream() + def outputStreamKind = RawStream() +} Modified: trunk/source/NMShell/src/info/ngms/commands/ls.scala =================================================================== --- trunk/source/NMShell/src/info/ngms/commands/ls.scala 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/NMShell/src/info/ngms/commands/ls.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -24,18 +24,18 @@ } def doWork( env : NMCommandContext ) : Unit = { - env.stdout match { - case NMRawStream(stream) => { - for(c <- "this is ls command\n") { - stream.write(c) - } - stream.close - } - case _ => - println("not support stream type") - } + env.stdout match { + case NMRawStream(stream) => { + for(c <- "this is ls command\n") { + stream.write(c) + } + stream.close + } + case _ => + println("not support stream type") + } } - def inputStreamKind = RawStream() - def outputStreamKind = RawStream() + def inputStreamKind = RawStream() + def outputStreamKind = RawStream() } Modified: trunk/source/NMShell/src/info/ngms/nmshell/Main.scala =================================================================== --- trunk/source/NMShell/src/info/ngms/nmshell/Main.scala 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/NMShell/src/info/ngms/nmshell/Main.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -5,42 +5,25 @@ package info.ngms.nmshell import info.ngms.nmtree.NMTree -import scala.concurrent.MailBox +import info.ngms.nmtree.NMPath +import info.ngms.nmtree.NMTreeImplementations - - -private class Pipe[T] extends Stream[T]{ - private case class End() - private case class Value(x : T) - private val mbox = new MailBox - - def write(x : T) { mbox send Value(x) } - def read() : Option[T] = { - mbox receive { x => - x match { - case Value(y) => - Some(y) - case End => - None - } - } - } - - def close { - mbox send End - } -} - - object Main { def main(args : Array[String]) : Unit = { NMTree.init( NMShellEnvironment ) + val root = new NMPath(NMPath.root) + val config : NMShellConfigFile = new NMShellConfigFile(NMShellConfigFile.defaultPath) + config.rootType match { + case NMTreeImplementations.RowFileSystem => + val fs = new info.ngms.nmtree.NMFileSystemTree( config.rootPath, root ) + NMTree.mount( root, fs ) + } while(true) mainLoop() } def showPrompt() : Unit = { - print("$ ") + print(NMShellEnvironment.currentPath.toString + " $") } def mainLoop() : Unit = { @@ -78,43 +61,42 @@ } private def connectCommandInstances( cmds : List[(NMCommand, NMCommandContext)] ) { - var stdin = NMShellEnvironment.stdin + var stdin = NMShellEnvironment.stdin var stdout = NMShellEnvironment.stdout - var stderr = NMShellEnvironment.stderr + var stderr = NMShellEnvironment.stderr cmds.head._2.stdin = stdin cmds.head._2.stderr = stderr - cmds.last._2.stdout = stdout + cmds.last._2.stdout = stdout cmds.zip(cmds.tail).foreach { - x => - val cmd1 = x._1._1 - val ctx1 = x._1._2 + x => + val cmd1 = x._1._1 + val ctx1 = x._1._2 + val cmd2 = x._2._1 + val ctx2 = x._2._2 - val cmd2 = x._2._1 - val ctx2 = x._2._2 - - if(cmd1.outputStreamKind == cmd2.inputStreamKind){ - ctx1.stdout = createStream(cmd1.outputStreamKind) - ctx2.stdin = ctx1.stdout - ctx2.stderr = stderr - }else{ - println("type mismatch") - println(" " + cmd1.name + " offered " + cmd1.outputStreamKind) - println(" " + cmd2.name + " required " + cmd2.inputStreamKind) - throw new Exception("") - } - } + if(cmd1.outputStreamKind == cmd2.inputStreamKind){ + ctx1.stdout = createStream(cmd1.outputStreamKind) + ctx2.stdin = ctx1.stdout + ctx2.stderr = stderr + }else{ + println("type mismatch") + println(" " + cmd1.name + " offered " + cmd1.outputStreamKind) + println(" " + cmd2.name + " required " + cmd2.inputStreamKind) + throw new Exception("") + } + } } private def createStream(kind : NMCommandStreamKind) : NMCommandStream = { - kind match { - case RawStream() => - NMRawStream(new Pipe) - case DescriptionStream() => - NMDescriptionStream(new Pipe) - case TableStream() => - NMTableStream(new Pipe) - } + kind match { + case RawStream() => + NMRawStream(new NMShellPipe) + case DescriptionStream() => + NMDescriptionStream(new NMShellPipe) + case TableStream() => + NMTableStream(new NMShellPipe) + } } def spawnCommand( cmdp : (NMCommand, NMCommandContext) ) : Unit = { Added: trunk/source/NMShell/src/info/ngms/nmshell/NMShellConfigFile.scala =================================================================== --- trunk/source/NMShell/src/info/ngms/nmshell/NMShellConfigFile.scala (rev 0) +++ trunk/source/NMShell/src/info/ngms/nmshell/NMShellConfigFile.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1,18 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmshell + +object NMShellConfigFile { + val defaultPath = "share/ngms/ngms.conf" +} + +/** + * ngms.confファイルを表現するクラス + */ +class NMShellConfigFile ( path : String ) { + // 未実装 + val rootPath = "/" + val rootType = info.ngms.nmtree.NMTreeImplementations.RowFileSystem +} \ No newline at end of file Modified: trunk/source/NMShell/src/info/ngms/nmshell/NMShellEnvironment.scala =================================================================== --- trunk/source/NMShell/src/info/ngms/nmshell/NMShellEnvironment.scala 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/NMShell/src/info/ngms/nmshell/NMShellEnvironment.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -5,6 +5,7 @@ package info.ngms.nmshell import info.ngms.nmtree.NMTree +import info.ngms.nmtree.NMPath import info.ngms.nmtree.NMTreeElements import info.ngms.nmtree.NMStreamElem import info.ngms.nmtree.NMTreeElements @@ -61,9 +62,9 @@ */ val stdin : NMCommandStream = { NMRawStream(new Stream[Int]{ - def read = Some(System.in.read) - def write(x : Int) = () - def close = () + def read = Some(System.in.read) + def write(x : Int) = () + def close = () }) } @@ -72,9 +73,9 @@ */ val stdout : NMCommandStream = { NMRawStream(new Stream[Int]{ - def read = None - def write(x : Int) = System.out.write(x) - def close = () + def read = None + def write(x : Int) = System.out.write(x) + def close = () }) } @@ -83,9 +84,14 @@ */ val stderr : NMCommandStream = { NMRawStream(new Stream[Int]{ - def read = None - def write(x : Int) = System.err.write(x) - def close = () + def read = None + def write(x : Int) = System.err.write(x) + def close = () }) } + + /** + * + */ + var currentPath : NMPath = new NMPath(NMPath.root) } Added: trunk/source/NMShell/src/info/ngms/nmshell/NMShellPipe.scala =================================================================== --- trunk/source/NMShell/src/info/ngms/nmshell/NMShellPipe.scala (rev 0) +++ trunk/source/NMShell/src/info/ngms/nmshell/NMShellPipe.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1,32 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmshell + +import scala.concurrent.MailBox + +/** + * スレッドセーフなパイプ + */ +class NMShellPipe[T] extends Stream[T]{ + private case class End() + private case class Value(x : T) + private val mbox = new MailBox + + def write(x : T) { mbox send Value(x) } + def read() : Option[T] = { + mbox receive { x => + x match { + case Value(y) => + Some(y) + case End => + None + } + } + } + + def close { + mbox send End + } +} Modified: trunk/source/NMTree/src/info/ngms/nmtree/NMDescription.scala =================================================================== --- trunk/source/NMTree/src/info/ngms/nmtree/NMDescription.scala 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/NMTree/src/info/ngms/nmtree/NMDescription.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -35,5 +35,5 @@ else new NMDescription(tag, parts(0).trim, parts(1).trim) } -} + } Modified: trunk/source/NMTree/src/info/ngms/nmtree/NMFileSystemTree.scala =================================================================== --- trunk/source/NMTree/src/info/ngms/nmtree/NMFileSystemTree.scala 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/NMTree/src/info/ngms/nmtree/NMFileSystemTree.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -47,16 +47,49 @@ } } + /** + * + */ + def fromFile2DescriptionElement(file : File) : NMTree.TDescriptionElement = { + import scala.io.Source + if (file.canRead() && file.isFile()) { + try { + val (h, b) = Source.fromFile(file).getLines.toList.break(_.trim.equals("")) + val lheader = { + val map = new LinkedHashMap[String, NMDescription]() + for (line <- h) { + line match { + case DescriptionElement(tag, value) => + map + (DescriptionElement.normalizeTag(tag) -> DescriptionElement.normalizeValue(tag, value)) + case _ => + () + } + } + map + } + val lbody = + b match { + case hd :: tl => tl + case Nil => Nil + } + new AbstractDescriptionElement { + val header = lheader + val body = lbody + def close : Unit = () + } + } catch { + case e: java.nio.BufferUnderflowException => // load binary file + throw new IllegalArgumentException("argument file is not text file.") + } + } else { + throw new IllegalArgumentException("argument file is not a file or cannot be read.") + } + } + def createDescription( path : NMPath ) : NMTree.TDescriptionElement = { val file = new File( path ) file.createNewFile() - val h = new LinkedHashMap[String, NMDescription]() - val b = Nil - new AbstractDescriptionElement { - val header = h - val body = b - def close : Unit = () - } + fromFile2DescriptionElement(file) } def createTable( path : NMPath ) : NMTree.TTableElement = { Modified: trunk/source/NMTree/src/info/ngms/nmtree/NMTree.scala =================================================================== --- trunk/source/NMTree/src/info/ngms/nmtree/NMTree.scala 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/NMTree/src/info/ngms/nmtree/NMTree.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -248,7 +248,7 @@ /** * 木構造の実装が必ず備えているべき変数、関数一覧 */ - type NMTreeImplimentation = { + type NMTreeImplementation = { def createStream( path : NMPath ) : TStreamElement def createDir( path : NMPath ) : Unit def createDescription( path : NMPath ) : TDescriptionElement @@ -287,8 +287,8 @@ } private[nmtree] object ImplMap { - val impls = scala.collection.mutable.Map.empty[String, NMTreeImplimentation] - def add( canonical : String, impl : NMTreeImplimentation ) : Unit = { + val impls = scala.collection.mutable.Map.empty[String, NMTreeImplementation] + def add( canonical : String, impl : NMTreeImplementation ) : Unit = { impls += ( canonical -> impl ) } def remove( canonical : String ) : Unit = { @@ -298,7 +298,7 @@ // 未実装 true } - def find( path : String ) : Option[NMTreeImplimentation] = { + def find( path : String ) : Option[NMTreeImplementation] = { impls.get( path ) match { case None => if( path.equals(NMPath.root) ) { @@ -310,7 +310,7 @@ } } - def withImpl[T] ( path : String, f : NMTreeImplimentation => T ) : T = { + def withImpl[T] ( path : String, f : NMTreeImplementation => T ) : T = { ImplMap.find(path) match { case None => throw new PathNotFoundException( path ) @@ -318,7 +318,7 @@ f( impl ) } } - def findSurely( path : String ) : NMTreeImplimentation = { + def findSurely( path : String ) : NMTreeImplementation = { withImpl( path, impl => impl ) } } @@ -339,7 +339,7 @@ ImplMap.withImpl( path.canonical, impl => impl.createTable( path ) ) } - def mount( path : NMPath , impl : NMTreeImplimentation ) : Unit = { + def mount( path : NMPath , impl : NMTreeImplementation ) : Unit = { ImplMap.add( path.canonical, impl ) } Added: trunk/source/NMTree/src/info/ngms/nmtree/NMTreeImplementations.scala =================================================================== --- trunk/source/NMTree/src/info/ngms/nmtree/NMTreeImplementations.scala (rev 0) +++ trunk/source/NMTree/src/info/ngms/nmtree/NMTreeImplementations.scala 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1,14 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + * See License file. + */ +package info.ngms.nmtree + +/** + * サポートしているNMTree実装の列挙 + */ +object NMTreeImplementations { + abstract class NMTreeImplementation + case object RowFileSystem extends NMTreeImplementation +} Added: trunk/source/README.txt =================================================================== --- trunk/source/README.txt (rev 0) +++ trunk/source/README.txt 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1,59 @@ + Next Generation Management System + +STATUS: + 2010-01-08 開発中 + +概要: + Next Generation Management System(NGMS)は、次世代のIT運用管理システム + です。 + + +インストール方法: + NGMSを利用するにはScala Version 2.7.6以上と次のライブラリが必要です。 + + - LOG4J version 1.2.14 + - SNMP4J version 1.10.2 + + これらのライブラリへクラスパスを通しておいてください。 + (現時点では不要. 2010-01-08) + + - Microsoft Windowsの場合 + 特にインストール作業は必要ありません。NGMSの配布物を展開したディレク + トリがNGMS用ディレクトリになります。bin\ngms.batをコマンドラインから + 起動して利用してください。 + + 共有のデータをSubversionからチェックアウトとして利用する方法などは、 + 利用の手引きを参照してください。 + + - Linuxの場合 + 特にインストール作業は必要ありません。NGMSの配布物を展開したディレク + トリがNGMS用ディレクトリになります。bin/ngmsをコマンドラインから起動 + して利用してください。 + + 同一のコンピューター上で複数人で利用したい場合は、bin/ディレクトリと + share/ディレクトリを/usr/localや/usrなどにコピーして利用してください。 + + 共有のデータをSubversionからチェックアウトとして利用する方法などは、 + 利用の手引きを参照してください。 + + +ビルド方法: + NGMSをソースコードからビルドして利用するには、実行環境に必要なライブ + ラリに加えてScalaTest Version 1.0及びantが必要になります。また、 + SCALA_HOME環境変数をScalaのインストールディレクトリに設定しておいてく + ださい。 + + 必要な環境がそろったら、NGMSの配布物を展開したディレクトリの直下から + $ant + のコマンドを実行してください。 + +ドキュメント: + +フィードバック: + バグレポート、ご意見、ご感想などNGMSのサイトにて受け付けております。 + + http://ngms.info/bbs/index.php + +著作権: + NGMS Project (c) 2009 All rights reserved. + Added: trunk/source/bin/ngms =================================================================== --- trunk/source/bin/ngms (rev 0) +++ trunk/source/bin/ngms 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1,3 @@ +#!/bin/sh +set libs=`dirname $0`/../share/ngms +scala -cp ${libs}/ngms.jar:${libs}extends/ info.ngms.nmshell.Main $* Added: trunk/source/bin/ngms.bat =================================================================== --- trunk/source/bin/ngms.bat (rev 0) +++ trunk/source/bin/ngms.bat 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1,2 @@ + @ echo off +scala -cp %~dp0..\share\ngms\ngms.jar;%~dp0..\share\ngms\extends\ info.ngms.nmshell.Main %* Modified: trunk/source/build.xml =================================================================== --- trunk/source/build.xml 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/build.xml 2010-01-08 13:08:53 UTC (rev 84) @@ -5,7 +5,9 @@ </target> <target name="compile" depends="initialize"> - <jar jarfile="ngms.jar" > + <ant dir="NMTree/" antfile="build.xml" target="all" /> + <ant dir="NMShell/" antfile="build.xml" target="all" /> + <jar jarfile="share/ngms/ngms.jar" > <fileset dir="NMTree/bin" /> <fileset dir="NMShell/bin" /> <manifest> Deleted: trunk/source/ngms.bat =================================================================== --- trunk/source/ngms.bat 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/ngms.bat 2010-01-08 13:08:53 UTC (rev 84) @@ -1,2 +0,0 @@ - @ echo off -scala -cp ngms.jar;extends/ info.ngms.nmshell.Main %* Deleted: trunk/source/ngms.sh =================================================================== --- trunk/source/ngms.sh 2009-12-28 11:37:26 UTC (rev 83) +++ trunk/source/ngms.sh 2010-01-08 13:08:53 UTC (rev 84) @@ -1 +0,0 @@ -scala -cp ngms.jar:extends/ info.ngms.nmshell.Main $* Added: trunk/source/share/ngms/data/config/group =================================================================== --- trunk/source/share/ngms/data/config/group (rev 0) +++ trunk/source/share/ngms/data/config/group 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1 @@ +wheel:root \ No newline at end of file Added: trunk/source/share/ngms/data/config/user =================================================================== --- trunk/source/share/ngms/data/config/user (rev 0) +++ trunk/source/share/ngms/data/config/user 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1 @@ +root:0: \ No newline at end of file Added: trunk/source/share/ngms/ngms.conf =================================================================== --- trunk/source/share/ngms/ngms.conf (rev 0) +++ trunk/source/share/ngms/ngms.conf 2010-01-08 13:08:53 UTC (rev 84) @@ -0,0 +1,2 @@ +RootPath: share/ngms/data +RootType: row \ No newline at end of file