use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class LocalDeploymentSpi method addResource.
/**
* Add new classes in class loader resource map.
* Note that resource map may contain two entries for one added class:
* task name -> class name and class name -> class name.
*
* @param ldr Registered class loader.
* @param ldrRsrcs Class loader resources.
* @param cls Registered classes collection.
* @return Map of new resources added for registered class loader.
* @throws org.apache.ignite.spi.IgniteSpiException If resource already registered. Exception thrown
* if registered resources conflicts with rule when all task classes must be
* annotated with different task names.
*/
@Nullable
private Map<String, String> addResource(ClassLoader ldr, ConcurrentMap<String, String> ldrRsrcs, Class<?> cls) throws IgniteSpiException {
assert ldr != null;
assert ldrRsrcs != null;
assert cls != null;
// Maps resources to classes.
// Map may contain 2 entries for one class.
Map<String, String> regRsrcs = U.newHashMap(2);
// Check alias collision for added classes.
String alias = null;
if (ComputeTask.class.isAssignableFrom(cls)) {
ComputeTaskName nameAnn = GridAnnotationsCache.getAnnotation(cls, ComputeTaskName.class);
if (nameAnn != null)
alias = nameAnn.value();
}
if (alias != null)
regRsrcs.put(alias, cls.getName());
regRsrcs.put(cls.getName(), cls.getName());
if (log.isDebugEnabled())
log.debug("Resources to register: " + regRsrcs);
Map<String, String> newRsrcs = null;
// Check collisions for added classes.
for (Entry<String, String> entry : regRsrcs.entrySet()) {
String oldCls = ldrRsrcs.putIfAbsent(entry.getKey(), entry.getValue());
if (oldCls != null) {
if (!oldCls.equals(entry.getValue())) {
throw new IgniteSpiException("Failed to register resources with given task name " + "(found another class with same task name in the same class loader) " + "[taskName=" + entry.getKey() + ", existingCls=" + oldCls + ", newCls=" + entry.getValue() + ", ldr=" + ldr + ']');
}
} else {
// New resource was added.
if (newRsrcs == null)
newRsrcs = U.newHashMap(regRsrcs.size());
newRsrcs.put(entry.getKey(), entry.getValue());
}
}
// New resources to register. Add it all.
if (newRsrcs != null)
ldrRsrcs.putAll(newRsrcs);
if (log.isDebugEnabled())
log.debug("New resources: " + newRsrcs);
return newRsrcs;
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridIoManager method send.
/**
* @param node Destination node.
* @param topic Topic to send the message to.
* @param topicOrd GridTopic enumeration ordinal.
* @param msg Message to send.
* @param plc Type of processing.
* @param ordered Ordered flag.
* @param timeout Timeout.
* @param skipOnTimeout Whether message can be skipped on timeout.
* @param ackC Ack closure.
* @param async If {@code true} message for local node will be processed in pool, otherwise in current thread.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
private void send(ClusterNode node, Object topic, int topicOrd, Message msg, byte plc, boolean ordered, long timeout, boolean skipOnTimeout, IgniteInClosure<IgniteException> ackC, boolean async) throws IgniteCheckedException {
assert node != null;
assert topic != null;
assert msg != null;
// Async execution was added only for IgniteMessaging.
assert !async || msg instanceof GridIoUserMessage : msg;
assert topicOrd >= 0 || !(topic instanceof GridTopic) : msg;
try (TraceSurroundings ignored = support(null)) {
MTC.span().addLog(() -> "Create communication msg - " + traceName(msg));
GridIoMessage ioMsg = createGridIoMessage(topic, topicOrd, msg, plc, ordered, timeout, skipOnTimeout);
if (locNodeId.equals(node.id())) {
assert plc != P2P_POOL;
CommunicationListener commLsnr = this.commLsnr;
if (commLsnr == null)
throw new IgniteCheckedException("Trying to send message when grid is not fully started.");
if (ordered)
processOrderedMessage(locNodeId, ioMsg, plc, null);
else if (async)
processRegularMessage(locNodeId, ioMsg, plc, NOOP);
else
processRegularMessage0(ioMsg, locNodeId);
if (ackC != null)
ackC.apply(null);
} else {
if (topicOrd < 0)
ioMsg.topicBytes(U.marshal(marsh, topic));
try {
if ((CommunicationSpi<?>) getSpi() instanceof TcpCommunicationSpi)
getTcpCommunicationSpi().sendMessage(node, ioMsg, ackC);
else
getSpi().sendMessage(node, ioMsg);
} catch (IgniteSpiException e) {
if (e.getCause() instanceof ClusterTopologyCheckedException)
throw (ClusterTopologyCheckedException) e.getCause();
if (!ctx.discovery().alive(node))
throw new ClusterTopologyCheckedException("Failed to send message, node left: " + node.id(), e);
throw new IgniteCheckedException("Failed to send message (node may have left the grid or " + "TCP connection cannot be established due to firewall issues) " + "[node=" + node + ", topic=" + topic + ", msg=" + msg + ", policy=" + plc + ']', e);
}
}
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridIoManager method openChannel.
/**
* @param nodeId Destination node to connect to.
* @param topic Topic to send the request to.
* @param initMsg Channel initialization message.
* @return Established {@link Channel} to use.
* @throws IgniteCheckedException If fails.
*/
private IgniteInternalFuture<Channel> openChannel(UUID nodeId, Object topic, Message initMsg) throws IgniteCheckedException {
assert nodeId != null;
assert topic != null;
assert !locNodeId.equals(nodeId) : "Channel cannot be opened to the local node itself: " + nodeId;
assert (CommunicationSpi) getSpi() instanceof TcpCommunicationSpi : "Only TcpCommunicationSpi supports direct " + "connections between nodes: " + getSpi().getClass();
ClusterNode node = ctx.discovery().node(nodeId);
if (node == null)
throw new ClusterTopologyCheckedException("Failed to open a new channel to remote node (node left): " + nodeId);
int topicOrd = topic instanceof GridTopic ? ((Enum<GridTopic>) topic).ordinal() : -1;
GridIoMessage ioMsg = createGridIoMessage(topic, topicOrd, initMsg, PUBLIC_POOL, false, 0, false);
try {
if (topicOrd < 0)
ioMsg.topicBytes(U.marshal(marsh, topic));
return ((TcpCommunicationSpi) (CommunicationSpi) getSpi()).openChannel(node, ioMsg);
} catch (IgniteSpiException e) {
if (e.getCause() instanceof ClusterTopologyCheckedException)
throw (ClusterTopologyCheckedException) e.getCause();
if (!ctx.discovery().alive(node))
throw new ClusterTopologyCheckedException("Failed to create channel (node left): " + node.id(), e);
throw new IgniteCheckedException("Failed to create channel (node may have left the grid or " + "TCP connection cannot be established due to unknown issues) " + "[node=" + node + ", topic=" + topic + ']', e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridDeploymentLocalStore method explicitDeploy.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public GridDeployment explicitDeploy(Class<?> cls, ClassLoader clsLdr) throws IgniteCheckedException {
try {
// if local one exists.
if (clsLdr.getClass().equals(GridDeploymentClassLoader.class))
clsLdr = clsLdr.getParent();
if (spi.register(clsLdr, cls)) {
if (log.isDebugEnabled()) {
log.debug("Resource registered automatically: [name=" + U.getResourceName(cls) + ", class=" + cls.getName() + ", ldr=" + clsLdr + ']');
}
}
GridDeploymentMetadata meta = new GridDeploymentMetadata();
meta.alias(cls.getName());
meta.classLoader(clsLdr);
GridDeployment dep = deployment(meta);
if (dep == null) {
dep = deploy(ctx.config().getDeploymentMode(), clsLdr, cls, U.getResourceName(cls), true);
}
return dep;
} catch (IgniteSpiException e) {
recordDeployFailed(cls, clsLdr, true);
// Avoid double wrapping.
if (e.getCause() instanceof IgniteCheckedException)
throw (IgniteCheckedException) e.getCause();
throw new IgniteDeploymentCheckedException("Failed to deploy class: " + cls.getName(), e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridDeploymentLocalStore method getDeployment.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public GridDeployment getDeployment(GridDeploymentMetadata meta) {
if (log.isDebugEnabled())
log.debug("Deployment meta for local deployment: " + meta);
String alias = meta.alias();
// Validate metadata.
assert alias != null : "Meta is invalid: " + meta;
GridDeployment dep = deployment(meta);
if (dep != null) {
if (log.isDebugEnabled())
log.debug("Acquired deployment class from local cache: " + dep);
return dep;
}
if (meta.classLoader() == null) {
DeploymentResource rsrc = spi.findResource(alias);
if (rsrc != null) {
dep = deploy(ctx.config().getDeploymentMode(), rsrc.getClassLoader(), rsrc.getResourceClass(), alias, meta.record());
assert dep != null;
if (log.isDebugEnabled())
log.debug("Acquired deployment class from SPI: " + dep);
return dep;
}
}
// Auto-deploy.
ClassLoader ldr = meta.classLoader();
if (ldr == null) {
ldr = Thread.currentThread().getContextClassLoader();
// Safety.
if (ldr == null)
ldr = U.resolveClassLoader(ctx.config());
}
if (ldr instanceof GridDeploymentClassLoader) {
if (log.isDebugEnabled())
log.debug("Skipping local auto-deploy (nested execution) [ldr=" + ldr + ", meta=" + meta + ']');
return null;
}
try {
// Check that class can be loaded.
String clsName = meta.className();
Class<?> cls = U.forName(clsName != null ? clsName : alias, ldr);
if (spi.register(ldr, cls)) {
if (log.isDebugEnabled()) {
log.debug("Resource registered automatically: [name=" + U.getResourceName(cls) + ", class=" + cls.getName() + ", ldr=" + ldr + ']');
}
}
dep = deploy(ctx.config().getDeploymentMode(), ldr, cls, alias, meta.record());
} catch (ClassNotFoundException ignored) {
if (log.isDebugEnabled())
log.debug("Failed to load class for local auto-deployment [ldr=" + ldr + ", meta=" + meta + ']');
return null;
} catch (IgniteSpiException e) {
U.error(log, "Failed to deploy local class with meta: " + meta, e);
return null;
}
if (log.isDebugEnabled())
log.debug("Acquired deployment class: " + dep);
return dep;
}
Aggregations