Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
tom
2014-10-07 17:43:48 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
53efab57e08cc7d181288d5dcb3fbf94fb1345d6
53efab57
1 parent
e279be89
Added Version and CoreService/Manager as an initial outline of a bootstrap coordinator.
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
253 additions
and
1 deletions
cli/src/main/java/org/onlab/onos/cli/SummaryCommand.java
core/api/src/main/java/org/onlab/onos/CoreService.java
core/api/src/main/java/org/onlab/onos/Version.java
core/api/src/test/java/org/onlab/onos/VersionTest.java
core/net/src/main/java/org/onlab/onos/cluster/impl/CoreManager.java
tools/build/onos-package
tools/package/bin/onos-service
utils/misc/src/main/java/org/onlab/util/Tools.java
cli/src/main/java/org/onlab/onos/cli/SummaryCommand.java
View file @
53efab5
package
org
.
onlab
.
onos
.
cli
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.CoreService
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.flow.FlowRuleService
;
...
...
@@ -21,7 +22,8 @@ public class SummaryCommand extends AbstractShellCommand {
protected
void
execute
()
{
TopologyService
topologyService
=
get
(
TopologyService
.
class
);
Topology
topology
=
topologyService
.
currentTopology
();
print
(
"nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d"
,
print
(
"version=%s, nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d"
,
get
(
CoreService
.
class
).
version
().
toString
(),
get
(
ClusterService
.
class
).
getNodes
().
size
(),
get
(
DeviceService
.
class
).
getDeviceCount
(),
get
(
LinkService
.
class
).
getLinkCount
(),
...
...
core/api/src/main/java/org/onlab/onos/CoreService.java
0 → 100644
View file @
53efab5
package
org
.
onlab
.
onos
;
/**
* Service for interacting with the core system of the controller.
*/
public
interface
CoreService
{
/**
* Returns the product version.
*
* @return product version
*/
Version
version
();
}
core/api/src/main/java/org/onlab/onos/Version.java
0 → 100644
View file @
53efab5
package
org
.
onlab
.
onos
;
import
java.util.Objects
;
import
static
java
.
lang
.
Integer
.
parseInt
;
/**
* Representation of the product version.
*/
public
final
class
Version
{
public
static
final
String
FORMAT
=
"%d.%d.%d.%s"
;
private
final
int
major
;
private
final
int
minor
;
private
final
int
patch
;
private
final
String
build
;
private
final
String
format
;
// Creates a new version descriptor
private
Version
(
int
major
,
int
minor
,
int
patch
,
String
build
)
{
this
.
major
=
major
;
this
.
minor
=
minor
;
this
.
patch
=
patch
;
this
.
build
=
build
;
this
.
format
=
String
.
format
(
FORMAT
,
major
,
minor
,
patch
,
build
);
}
/**
* Creates a new version from the specified constituent numbers.
*
* @param major major version number
* @param minor minod version number
* @param patch version patch number
* @param build build string
* @return version descriptor
*/
public
static
Version
version
(
int
major
,
int
minor
,
int
patch
,
String
build
)
{
return
new
Version
(
major
,
minor
,
patch
,
build
);
}
/**
* Creates a new version by parsing the specified string.
*
* @param string version string
* @return version descriptor
*/
public
static
Version
version
(
String
string
)
{
String
[]
fields
=
string
.
split
(
"[.-]"
);
return
new
Version
(
parseInt
(
fields
[
0
]),
parseInt
(
fields
[
1
]),
parseInt
(
fields
[
2
]),
fields
[
3
]);
}
/**
* Returns the major version number.
*
* @return major version number
*/
public
int
major
()
{
return
major
;
}
/**
* Returns the minor version number.
*
* @return minor version number
*/
public
int
minor
()
{
return
minor
;
}
/**
* Returns the version patch number.
*
* @return patch number
*/
public
int
patch
()
{
return
patch
;
}
/**
* Returns the version build string.
*
* @return build string
*/
public
String
build
()
{
return
build
;
}
@Override
public
String
toString
()
{
return
format
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
format
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
instanceof
Version
)
{
final
Version
other
=
(
Version
)
obj
;
return
Objects
.
equals
(
this
.
format
,
other
.
format
);
}
return
false
;
}
}
core/api/src/test/java/org/onlab/onos/VersionTest.java
0 → 100644
View file @
53efab5
package
org
.
onlab
.
onos
;
import
com.google.common.testing.EqualsTester
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
onlab
.
onos
.
Version
.
version
;
/**
* Tests of the version descriptor.
*/
public
class
VersionTest
{
@Test
public
void
fromParts
()
{
Version
v
=
version
(
1
,
2
,
3
,
"4321"
);
assertEquals
(
"wrong major"
,
1
,
v
.
major
());
assertEquals
(
"wrong minor"
,
2
,
v
.
minor
());
assertEquals
(
"wrong patch"
,
3
,
v
.
patch
());
assertEquals
(
"wrong build"
,
"4321"
,
v
.
build
());
}
@Test
public
void
fromString
()
{
Version
v
=
version
(
"1.2.3.4321"
);
assertEquals
(
"wrong major"
,
1
,
v
.
major
());
assertEquals
(
"wrong minor"
,
2
,
v
.
minor
());
assertEquals
(
"wrong patch"
,
3
,
v
.
patch
());
assertEquals
(
"wrong build"
,
"4321"
,
v
.
build
());
}
@Test
public
void
snapshot
()
{
Version
v
=
version
(
"1.2.3-SNAPSHOT"
);
assertEquals
(
"wrong major"
,
1
,
v
.
major
());
assertEquals
(
"wrong minor"
,
2
,
v
.
minor
());
assertEquals
(
"wrong patch"
,
3
,
v
.
patch
());
assertEquals
(
"wrong build"
,
"SNAPSHOT"
,
v
.
build
());
}
@Test
public
void
testEquals
()
{
new
EqualsTester
()
.
addEqualityGroup
(
version
(
"1.2.3.4321"
),
version
(
1
,
2
,
3
,
"4321"
))
.
addEqualityGroup
(
version
(
"1.9.3.4321"
),
version
(
1
,
9
,
3
,
"4321"
))
.
addEqualityGroup
(
version
(
"1.2.8.4321"
),
version
(
1
,
2
,
8
,
"4321"
))
.
addEqualityGroup
(
version
(
"1.2.3.x"
),
version
(
1
,
2
,
3
,
"x"
))
.
testEquals
();
}
}
\ No newline at end of file
core/net/src/main/java/org/onlab/onos/cluster/impl/CoreManager.java
0 → 100644
View file @
53efab5
package
org
.
onlab
.
onos
.
cluster
.
impl
;
import
org.apache.felix.scr.annotations.Activate
;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Service
;
import
org.onlab.onos.CoreService
;
import
org.onlab.onos.Version
;
import
org.onlab.util.Tools
;
import
java.io.File
;
import
java.util.List
;
/**
* Core service implementation.
*/
@Component
@Service
public
class
CoreManager
implements
CoreService
{
private
static
final
File
VERSION_FILE
=
new
File
(
"../VERSION"
);
private
static
Version
version
=
Version
.
version
(
"1.0.0-SNAPSHOT"
);
// TODO: work in progress
@Activate
public
void
activate
()
{
List
<
String
>
versionLines
=
Tools
.
slurp
(
VERSION_FILE
);
if
(
versionLines
!=
null
&&
!
versionLines
.
isEmpty
())
{
version
=
Version
.
version
(
versionLines
.
get
(
0
));
}
}
@Override
public
Version
version
()
{
return
version
;
}
}
tools/build/onos-package
View file @
53efab5
...
...
@@ -60,6 +60,13 @@ perl -pi.old -e "s|^(featuresBoot=.*)|\1,$ONOS_FEATURES|" \
cp
$M2_REPO
/org/onlab/onos/onos-branding/
$ONOS_VERSION
/onos-branding-
*
.jar
\
$ONOS_STAGE
/
$KARAF_DIST
/lib
# Patch in the ONOS version file use the build number or the user name for
# build postfix in place of the SNAPSHOT post-fix.
build
=
${
BUILD_NUMBER
:-$(
id -un
)}
grep
'<version>'
$ONOS_ROOT
/pom.xml | head -n1 |
\
sed
's:.*<version>::g;s:</version>.*::g'
| sed
"s/SNAPSHOT/
$build
/g"
\
>>
$ONOS_STAGE
/VERSION
# Now package up the ONOS tar file
cd
$ONOS_STAGE_ROOT
COPYFILE_DISABLE
=
1 tar zcf
$ONOS_TAR
$ONOS_BITS
...
...
tools/package/bin/onos-service
View file @
53efab5
...
...
@@ -4,6 +4,7 @@
#-------------------------------------------------------------------------------
export
JAVA_HOME
=
${
JAVA_HOME
:-
/usr/lib/jvm/java-7-openjdk-amd64/
}
export
JAVA_OPTS
=
"-Xms256M -Xmx2048M"
cd
/opt/onos
/opt/onos/apache-karaf-3.0.1/bin/karaf
"
$@
"
...
...
utils/misc/src/main/java/org/onlab/util/Tools.java
View file @
53efab5
...
...
@@ -4,6 +4,12 @@ import com.google.common.base.Strings;
import
com.google.common.primitives.UnsignedLongs
;
import
com.google.common.util.concurrent.ThreadFactoryBuilder
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.ThreadFactory
;
public
abstract
class
Tools
{
...
...
@@ -66,4 +72,24 @@ public abstract class Tools {
}
}
/**
* Slurps the contents of a file into a list of strings, one per line.
*
* @param path file path
* @return file contents
*/
public
static
List
<
String
>
slurp
(
File
path
)
{
try
(
BufferedReader
br
=
new
BufferedReader
(
new
FileReader
(
path
)))
{
List
<
String
>
lines
=
new
ArrayList
<>();
String
line
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
lines
.
add
(
line
);
}
return
lines
;
}
catch
(
IOException
e
)
{
return
null
;
}
}
}
...
...
Please
register
or
login
to post a comment