Skip to content

Commit

Permalink
# IGNITE-187 Moved node attrs to manager start().
Browse files Browse the repository at this point in the history
  • Loading branch information
akuznetsov-gridgain committed Feb 27, 2015
1 parent 651b252 commit a9db397
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 85 deletions.
Expand Up @@ -534,13 +534,6 @@ public interface GridKernalContext extends Iterable<GridComponent> {
*/
public Object addNodeAttribute(String key, Object val);

/**
* Add attributes to node attributes.
*
* @param attrs Attributes to add.
*/
public void addNodeAttributes(Map<String, String> attrs);

/**
* @return Node attributes.
*/
Expand Down
Expand Up @@ -866,17 +866,11 @@ protected Object readResolve() throws ObjectStreamException {
return attrs.containsKey(key);
}


/** {@inheritDoc} */
@Override public Object addNodeAttribute(String key, Object val) {
return attrs.put(key, val);
}

/** {@inheritDoc} */
@Override public void addNodeAttributes(Map<String, String> attrs) {
this.attrs.putAll(attrs);
}

/** {@inheritDoc} */
@Override public Map<String, Object> nodeAttributes() {
return attrs;
Expand Down
Expand Up @@ -1103,12 +1103,13 @@ private void fillNodeAttributes() throws IgniteCheckedException {

try {
// Stick all environment settings into node attributes.
ctx.addNodeAttributes(F.view(System.getenv(), new P1<String>() {
@Override public boolean apply(String name) {
return incProps == null || U.containsStringArray(incProps, name, true) ||
U.isVisorNodeStartProperty(name) || U.isVisorRequiredProperty(name);
}
}));
for (Map.Entry<String, String> sysEntry : System.getenv().entrySet()) {
String name = sysEntry.getKey();

if (incProps == null || U.containsStringArray(incProps, name, true) ||
U.isVisorNodeStartProperty(name) || U.isVisorRequiredProperty(name))
ctx.addNodeAttribute(name, sysEntry.getValue());
}

if (log.isDebugEnabled())
log.debug("Added environment properties to node attributes.");
Expand Down Expand Up @@ -1375,16 +1376,8 @@ private boolean unregisterMBean(@Nullable ObjectName mbean) {
* @throws IgniteCheckedException Throw in case of any errors.
*/
private void startManager(GridManager mgr) throws IgniteCheckedException {
mgr.addSpiAttributes();

// Set all node attributes into discovery manager,
// so they can be distributed to all nodes.
if (mgr instanceof GridDiscoveryManager)
((GridDiscoveryManager)mgr).setNodeAttributes(VER);

// Add manager to registry before it starts to avoid
// cases when manager is started but registry does not
// have it yet.
// Add manager to registry before it starts to avoid cases when manager is started
// but registry does not have it yet.
ctx.add(mgr);

try {
Expand Down
Expand Up @@ -31,15 +31,7 @@
@GridToStringExclude
public interface GridManager extends GridComponent {
/**
* Adds attributes from underlying SPI to node attributes.
*
* @throws IgniteCheckedException Wrapper for exception thrown by underlying SPI.
*/
public void addSpiAttributes() throws IgniteCheckedException;

/**
* @return Returns {@code true} if at least one SPI does not have a {@code NO-OP}
* implementation, {@code false} otherwise.
* @return {@code true} if at least one SPI does not have a {@code NO-OP} implementation, {@code false} otherwise.
*/
public boolean enabled();
}
Expand Up @@ -90,6 +90,38 @@ protected GridManagerAdapter(GridKernalContext ctx, T... spis) {
log = ctx.log(getClass());
}

/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
for (T spi : spis) {
// Inject all spi resources.
ctx.resource().inject(spi);

// Inject SPI internal objects.
inject(spi);

try {
Map<String, Object> retval = spi.getNodeAttributes();

if (retval != null) {
for (Map.Entry<String, Object> e : retval.entrySet()) {
if (ctx.hasNodeAttribute(e.getKey()))
throw new IgniteCheckedException("SPI attribute collision for attribute [spi=" + spi +
", attr=" + e.getKey() + ']' +
". Attribute set by one SPI implementation has the same name (name collision) as " +
"attribute set by other SPI implementation. Such overriding is not allowed. " +
"Please check your Ignite configuration and/or SPI implementation to avoid " +
"attribute name collisions.");

ctx.addNodeAttribute(e.getKey(), e.getValue());
}
}
}
catch (IgniteSpiException e) {
throw new IgniteCheckedException("Failed to get SPI attributes.", e);
}
}
}

/**
* Gets wrapped SPI.
*
Expand Down Expand Up @@ -130,38 +162,6 @@ protected final T[] getSpis() {
return spis;
}

/** {@inheritDoc} */
@Override public final void addSpiAttributes() throws IgniteCheckedException {
for (T spi : spis) {
// Inject all spi resources.
ctx.resource().inject(spi);

// Inject SPI internal objects.
inject(spi);

try {
Map<String, Object> retval = spi.getNodeAttributes();

if (retval != null) {
for (Map.Entry<String, Object> e : retval.entrySet()) {
if (ctx.hasNodeAttribute(e.getKey()))
throw new IgniteCheckedException("SPI attribute collision for attribute [spi=" + spi +
", attr=" + e.getKey() + ']' +
". Attribute set by one SPI implementation has the same name (name collision) as " +
"attribute set by other SPI implementation. Such overriding is not allowed. " +
"Please check your Ignite configuration and/or SPI implementation to avoid " +
"attribute name collisions.");

ctx.addNodeAttribute(e.getKey(), e.getValue());
}
}
}
catch (IgniteSpiException e) {
throw new IgniteCheckedException("Failed to get SPI attributes.", e);
}
}
}

/**
* @param spi SPI whose internal objects need to be injected.
* @throws IgniteCheckedException If injection failed.
Expand Down
Expand Up @@ -78,6 +78,8 @@ public GridCheckpointManager(GridKernalContext ctx) {
if (ctx.config().isDaemon())
return;

super.start();

for (CheckpointSpi spi : getSpis()) {
spi.setCheckpointListener(new CheckpointListener() {
@Override public void onCheckpointRemoved(String key) {
Expand Down
Expand Up @@ -47,6 +47,8 @@ public GridCollisionManager(GridKernalContext ctx) {
if (ctx.config().isDaemon())
return;

super.start();

startSpi();

if (enabled()) {
Expand Down
Expand Up @@ -179,6 +179,8 @@ public void resetMetrics() {
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override public void start() throws IgniteCheckedException {
super.start();

assertParameter(discoDelay > 0, "discoveryStartupDelay > 0");

startSpi();
Expand Down
Expand Up @@ -81,6 +81,8 @@ public GridDeploymentManager(GridKernalContext ctx) {

/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
super.start();

GridProtocolHandler.registerDeploymentManager(this);

assertParameter(ctx.config().getDeploymentMode() != null, "ctx.config().getDeploymentMode() != null");
Expand Down
Expand Up @@ -53,6 +53,7 @@
import static java.util.concurrent.TimeUnit.*;
import static org.apache.ignite.events.EventType.*;
import static org.apache.ignite.internal.IgniteNodeAttributes.*;
import static org.apache.ignite.internal.IgniteVersionUtils.*;
import static org.apache.ignite.plugin.segmentation.GridSegmentationPolicy.*;

/**
Expand Down Expand Up @@ -189,12 +190,10 @@ private MemoryUsage nonHeapMemoryUsage() {
}
}

/**
* Sets local node attributes into discovery SPI.
*
* @param ver Version.
*/
public void setNodeAttributes(IgniteProductVersion ver) {
/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
super.start();

// TODO GG-7574 move to metrics processor?
long totSysMemory = -1;

Expand All @@ -207,11 +206,10 @@ public void setNodeAttributes(IgniteProductVersion ver) {

ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_PHY_RAM, totSysMemory);

getSpi().setNodeAttributes(ctx.nodeAttributes(), ver);
}
DiscoverySpi spi = getSpi();

spi.setNodeAttributes(ctx.nodeAttributes(), VER);

/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
discoOrdered = discoOrdered();

histSupported = historySupported();
Expand All @@ -235,10 +233,10 @@ public void setNodeAttributes(IgniteProductVersion ver) {

new IgniteThread(metricsUpdater).start();

getSpi().setMetricsProvider(createMetricsProvider());
spi.setMetricsProvider(createMetricsProvider());

if (ctx.security().enabled()) {
getSpi().setAuthenticator(new DiscoverySpiNodeAuthenticator() {
spi.setAuthenticator(new DiscoverySpiNodeAuthenticator() {
@Override public SecurityContext authenticateNode(ClusterNode node, GridSecurityCredentials cred) {
try {
return ctx.security().authenticateNode(node, cred);
Expand All @@ -254,7 +252,7 @@ public void setNodeAttributes(IgniteProductVersion ver) {
});
}

getSpi().setListener(new DiscoverySpiListener() {
spi.setListener(new DiscoverySpiListener() {
@Override public void onDiscovery(
int type,
long topVer,
Expand Down Expand Up @@ -315,7 +313,7 @@ public void setNodeAttributes(IgniteProductVersion ver) {
}
});

getSpi().setDataExchange(new DiscoverySpiDataExchange() {
spi.setDataExchange(new DiscoverySpiDataExchange() {
@Override public Map<Integer, Object> collect(UUID nodeId) {
assert nodeId != null;

Expand Down Expand Up @@ -367,7 +365,7 @@ public void setNodeAttributes(IgniteProductVersion ver) {

checkAttributes(discoCache().remoteNodes());

locNode = getSpi().getLocalNode();
locNode = spi.getLocalNode();

topVer.setIfGreater(locNode.order());

Expand Down
Expand Up @@ -222,6 +222,8 @@ private void leaveBusy() {

/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
super.start();

Map<IgnitePredicate<? extends Event>, int[]> evtLsnrs = ctx.config().getLocalEventListeners();

if (evtLsnrs != null) {
Expand Down
Expand Up @@ -39,6 +39,8 @@ public GridFailoverManager(GridKernalContext ctx) {

/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
super.start();

startSpi();

if (log.isDebugEnabled())
Expand Down
Expand Up @@ -48,6 +48,8 @@ public GridIndexingManager(GridKernalContext ctx) {
if (ctx.config().isDaemon())
return;

super.start();

if (!enabled())
U.warn(log, "Indexing is disabled (to enable please configure GridIndexingSpi).");

Expand Down
Expand Up @@ -45,6 +45,8 @@ public GridLoadBalancerManager(GridKernalContext ctx) {

/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
super.start();

startSpi();

if (log.isDebugEnabled())
Expand Down
Expand Up @@ -53,6 +53,8 @@ public GridSwapSpaceManager(GridKernalContext ctx) {
if (ctx.config().isDaemon())
return;

super.start();

getSpi().setListener(new SwapSpaceSpiListener() {
@Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable byte[] keyBytes) {
if (ctx.event().isRecordable(evtType)) {
Expand Down

0 comments on commit a9db397

Please sign in to comment.