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



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


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

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


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


if (log.isDebugEnabled()) if (log.isDebugEnabled())
log.debug("Added environment properties to node attributes."); 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. * @throws IgniteCheckedException Throw in case of any errors.
*/ */
private void startManager(GridManager mgr) throws IgniteCheckedException { private void startManager(GridManager mgr) throws IgniteCheckedException {
mgr.addSpiAttributes(); // Add manager to registry before it starts to avoid cases when manager is started

// but registry does not have it yet.
// 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.
ctx.add(mgr); ctx.add(mgr);


try { try {
Expand Down
Expand Up @@ -31,15 +31,7 @@
@GridToStringExclude @GridToStringExclude
public interface GridManager extends GridComponent { public interface GridManager extends GridComponent {
/** /**
* Adds attributes from underlying SPI to node attributes. * @return {@code true} if at least one SPI does not have a {@code NO-OP} implementation, {@code false} otherwise.
*
* @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.
*/ */
public boolean enabled(); public boolean enabled();
} }
Expand Up @@ -90,6 +90,38 @@ protected GridManagerAdapter(GridKernalContext ctx, T... spis) {
log = ctx.log(getClass()); 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. * Gets wrapped SPI.
* *
Expand Down Expand Up @@ -130,38 +162,6 @@ protected final T[] getSpis() {
return spis; 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. * @param spi SPI whose internal objects need to be injected.
* @throws IgniteCheckedException If injection failed. * @throws IgniteCheckedException If injection failed.
Expand Down
Expand Up @@ -78,6 +78,8 @@ public GridCheckpointManager(GridKernalContext ctx) {
if (ctx.config().isDaemon()) if (ctx.config().isDaemon())
return; return;


super.start();

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


super.start();

startSpi(); startSpi();


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

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


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


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

GridProtocolHandler.registerDeploymentManager(this); GridProtocolHandler.registerDeploymentManager(this);


assertParameter(ctx.config().getDeploymentMode() != null, "ctx.config().getDeploymentMode() != null"); 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 java.util.concurrent.TimeUnit.*;
import static org.apache.ignite.events.EventType.*; import static org.apache.ignite.events.EventType.*;
import static org.apache.ignite.internal.IgniteNodeAttributes.*; import static org.apache.ignite.internal.IgniteNodeAttributes.*;
import static org.apache.ignite.internal.IgniteVersionUtils.*;
import static org.apache.ignite.plugin.segmentation.GridSegmentationPolicy.*; import static org.apache.ignite.plugin.segmentation.GridSegmentationPolicy.*;


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


/** /** {@inheritDoc} */
* Sets local node attributes into discovery SPI. @Override public void start() throws IgniteCheckedException {
* super.start();
* @param ver Version.
*/
public void setNodeAttributes(IgniteProductVersion ver) {
// TODO GG-7574 move to metrics processor? // TODO GG-7574 move to metrics processor?
long totSysMemory = -1; long totSysMemory = -1;


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


ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_PHY_RAM, totSysMemory); 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(); discoOrdered = discoOrdered();


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


new IgniteThread(metricsUpdater).start(); new IgniteThread(metricsUpdater).start();


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


if (ctx.security().enabled()) { if (ctx.security().enabled()) {
getSpi().setAuthenticator(new DiscoverySpiNodeAuthenticator() { spi.setAuthenticator(new DiscoverySpiNodeAuthenticator() {
@Override public SecurityContext authenticateNode(ClusterNode node, GridSecurityCredentials cred) { @Override public SecurityContext authenticateNode(ClusterNode node, GridSecurityCredentials cred) {
try { try {
return ctx.security().authenticateNode(node, cred); 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( @Override public void onDiscovery(
int type, int type,
long topVer, 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) { @Override public Map<Integer, Object> collect(UUID nodeId) {
assert nodeId != null; assert nodeId != null;


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


checkAttributes(discoCache().remoteNodes()); checkAttributes(discoCache().remoteNodes());


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


topVer.setIfGreater(locNode.order()); topVer.setIfGreater(locNode.order());


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


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

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


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


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

startSpi(); startSpi();


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


super.start();

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


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


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

startSpi(); startSpi();


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


super.start();

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

0 comments on commit a9db397

Please sign in to comment.