/** * Register operation, future and add operation worker to execute queue. * * @param op User operation. */ private void submitOperation(UserManagementOperation op) { synchronized (mux) { UserOperationFinishFuture fut = opFinishFuts.get(op.id()); if (fut == null) { fut = new UserOperationFinishFuture(op.id()); opFinishFuts.put(op.id(), fut); } if (!fut.workerSubmitted()) { fut.workerSubmitted(true); activeOps.put(op.id(), op); exec.execute(new UserOperationWorker(op, fut)); } } }
/** * @param nodeId Node ID. * @param errMsg Error message. */ synchronized void onOperationFailOnNode(UUID nodeId, String errMsg) { assert receivedFinish != null : "Process operation state on client"; if (log.isDebugEnabled()) log.debug("User operation is failed [nodeId=" + nodeId + ", err=" + errMsg + ']'); receivedFinish.add(nodeId); UserManagementException e = new UserManagementException("Operation failed [nodeId=" + nodeId + ", opId=" + opId + ", err=" + errMsg + ']'); if (err == null) err = e; else err.addSuppressed(e); checkOperationFinished(); }
/** * @param msg Error message. */ private void cancelFutures(String msg) { synchronized (mux) { for (UserOperationFinishFuture fut : opFinishFuts.values()) fut.onDone(null, new IgniteFutureCancelledException(msg)); } for (GridFutureAdapter<Void> fut : authFuts.values()) fut.onDone(null, new IgniteFutureCancelledException(msg)); }
/** * @param nodeId Left node ID. */ private void onNodeLeft(UUID nodeId) { synchronized (mux) { if (!ctx.clientNode()) { for (UserOperationFinishFuture f : opFinishFuts.values()) f.onNodeLeft(nodeId); } // Found all auth requests that were be sent to left node. // Complete these futures with special exception to retry authentication. for (Iterator<Map.Entry<IgniteUuid, AuthenticateFuture>> it = authFuts.entrySet().iterator(); it.hasNext(); ) { AuthenticateFuture f = it.next().getValue(); if (F.eq(nodeId, f.nodeId())) { f.retry(true); f.onDone(); it.remove(); } } // Coordinator left if (F.eq(coordinator().id(), nodeId)) { // Refresh info about coordinator node. crdNode = null; if (curOpFinishMsg != null) sendFinish(curOpFinishMsg); } } }
/** * @param op User operation. * @return Operation future. * @throws IgniteCheckedException On error. */ private UserOperationFinishFuture execUserOperation(UserManagementOperation op) throws IgniteCheckedException { checkActivate(); checkEnabled(); synchronized (mux) { if (disconnected) { throw new UserManagementException("Failed to initiate user management operation because " + "client node is disconnected."); } AuthorizationContext actx = AuthorizationContext.context(); if (actx == null) throw new IgniteAccessControlException("Operation not allowed: authorized context is empty."); actx.checkUserOperation(op); UserOperationFinishFuture fut = new UserOperationFinishFuture(op.id()); opFinishFuts.put(op.id(), fut); UserProposedMessage msg = new UserProposedMessage(op); ctx.discovery().sendCustomEvent(msg); return fut; } }
/** * Handle finish operation message from a node. * * @param nodeId Node ID. * @param msg Message. */ private void onFinishMessage(UUID nodeId, UserManagementOperationFinishedMessage msg) { if (log.isDebugEnabled()) log.debug(msg.toString()); synchronized (mux) { UserOperationFinishFuture fut = opFinishFuts.get(msg.operationId()); if (fut == null) { fut = new UserOperationFinishFuture(msg.operationId()); opFinishFuts.put(msg.operationId(), fut); } if (msg.success()) fut.onSuccessOnNode(nodeId); else fut.onOperationFailOnNode(nodeId, msg.errorMessage()); } }
/** * Register operation, future and add operation worker to execute queue. * * @param op User operation. */ private void submitOperation(UserManagementOperation op) { synchronized (mux) { UserOperationFinishFuture fut = opFinishFuts.get(op.id()); if (fut == null) { fut = new UserOperationFinishFuture(op.id()); opFinishFuts.put(op.id(), fut); } if (!fut.workerSubmitted()) { fut.workerSubmitted(true); activeOps.put(op.id(), op); exec.execute(new UserOperationWorker(op, fut)); } } }
/** * @param nodeId Node ID. * @param errMsg Error message. */ synchronized void onOperationFailOnNode(UUID nodeId, String errMsg) { assert receivedFinish != null : "Process operation state on client"; if (log.isDebugEnabled()) log.debug("User operation is failed [nodeId=" + nodeId + ", err=" + errMsg + ']'); receivedFinish.add(nodeId); UserManagementException e = new UserManagementException("Operation failed [nodeId=" + nodeId + ", opId=" + opId + ", err=" + errMsg + ']'); if (err == null) err = e; else err.addSuppressed(e); checkOperationFinished(); }
/** {@inheritDoc} */ @Override public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, UserAcceptedMessage msg) { if (!isEnabled || ctx.isStopping()) return; if (log.isDebugEnabled()) log.debug(msg.toString()); synchronized (mux) { UserOperationFinishFuture f = opFinishFuts.get(msg.operationId()); if (f != null) { if (msg.error() != null) f.onDone(null, msg.error()); else f.onDone(); } } } }
/** * Adds new user. * * @param login User's login. * @param passwd Plain text password. * @throws IgniteCheckedException On error. */ public void addUser(String login, String passwd) throws IgniteCheckedException { validate(login, passwd); UserManagementOperation op = new UserManagementOperation(User.create(login, passwd), UserManagementOperation.OperationType.ADD); execUserOperation(op).get(); }
/** * @param nodeId ID of left or failed node. */ synchronized void onNodeLeft(UUID nodeId) { assert requiredFinish != null : "Process node left on client"; requiredFinish.remove(nodeId); checkOperationFinished(); }
/** * @param nodeId Node ID. */ synchronized void onSuccessOnNode(UUID nodeId) { assert receivedFinish != null : "Process operation state on client"; receivedFinish.add(nodeId); checkOperationFinished(); }
/** * @param login User name. * @param passwd User password. * @throws IgniteCheckedException On error. */ public void updateUser(String login, String passwd) throws IgniteCheckedException { UserManagementOperation op = new UserManagementOperation(User.create(login, passwd), UserManagementOperation.OperationType.UPDATE); execUserOperation(op).get(); }
/** * @param login User name. * @throws IgniteCheckedException On error. */ public void removeUser(String login) throws IgniteCheckedException { UserManagementOperation op = new UserManagementOperation(User.create(login), UserManagementOperation.OperationType.REMOVE); execUserOperation(op).get(); }
/** * @param node Joined node ID. */ private void onNodeJoin(ClusterNode node) { if (isNodeHoldsUsers(ctx.discovery().localNode()) && isNodeHoldsUsers(node)) { synchronized (mux) { for (UserOperationFinishFuture f : opFinishFuts.values()) f.onNodeJoin(node.id()); } } }
/** * @param msg Error message. */ private void cancelFutures(String msg) { synchronized (mux) { for (UserOperationFinishFuture fut : opFinishFuts.values()) fut.onDone(null, new IgniteFutureCancelledException(msg)); } for (GridFutureAdapter<Void> fut : authFuts.values()) fut.onDone(null, new IgniteFutureCancelledException(msg)); }
fut.get();
/** * @param nodeId Left node ID. */ private void onNodeLeft(UUID nodeId) { synchronized (mux) { if (!ctx.clientNode()) { for (UserOperationFinishFuture f : opFinishFuts.values()) f.onNodeLeft(nodeId); } // Found all auth requests that were be sent to left node. // Complete these futures with special exception to retry authentication. for (Iterator<Map.Entry<IgniteUuid, AuthenticateFuture>> it = authFuts.entrySet().iterator(); it.hasNext(); ) { AuthenticateFuture f = it.next().getValue(); if (F.eq(nodeId, f.nodeId())) { f.retry(true); f.onDone(); it.remove(); } } // Coordinator left if (F.eq(coordinator().id(), nodeId)) { // Refresh info about coordinator node. crdNode = null; if (curOpFinishMsg != null) sendFinish(curOpFinishMsg); } } }
/** * @param op User operation. * @return Operation future. * @throws IgniteCheckedException On error. */ private UserOperationFinishFuture execUserOperation(UserManagementOperation op) throws IgniteCheckedException { checkActivate(); checkEnabled(); synchronized (mux) { if (disconnected) { throw new UserManagementException("Failed to initiate user management operation because " + "client node is disconnected."); } AuthorizationContext actx = AuthorizationContext.context(); if (actx == null) throw new IgniteAccessControlException("Operation not allowed: authorized context is empty."); actx.checkUserOperation(op); UserOperationFinishFuture fut = new UserOperationFinishFuture(op.id()); opFinishFuts.put(op.id(), fut); UserProposedMessage msg = new UserProposedMessage(op); ctx.discovery().sendCustomEvent(msg); return fut; } }