use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.
the class IgniteUtils method formatMins.
/**
* Pretty-formatting for minutes.
*
* @param mins Minutes to format.
* @return Formatted presentation of minutes.
*/
public static String formatMins(long mins) {
assert mins >= 0;
if (mins == 0)
return "< 1 min";
SB sb = new SB();
// 1440 mins = 60 mins * 24 hours
long dd = mins / 1440;
if (dd > 0)
sb.a(dd).a(dd == 1 ? " day " : " days ");
mins %= 1440;
long hh = mins / 60;
if (hh > 0)
sb.a(hh).a(hh == 1 ? " hour " : " hours ");
mins %= 60;
if (mins > 0)
sb.a(mins).a(mins == 1 ? " min " : " mins ");
return sb.toString().trim();
}
use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.
the class GridLongList method toString.
/** {@inheritDoc} */
@Override
public String toString() {
SB b = new SB("[");
for (int i = 0; i < idx; i++) {
if (i != 0)
b.a(',');
b.a(arr[i]);
}
b.a(']');
return S.toString(GridLongList.class, this, "arr", b);
}
use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.
the class IgniteUtils method quiet.
/**
*
* @param err Whether to print to {@code System.err}.
* @param objs Objects to log in quiet mode.
*/
public static void quiet(boolean err, Object... objs) {
assert objs != null;
String time = SHORT_DATE_FMT.format(new java.util.Date());
SB sb = new SB();
for (Object obj : objs) sb.a('[').a(time).a("] ").a(obj.toString()).a(NL);
PrintStream ps = err ? System.err : System.out;
ps.print(compact(sb.toString()));
}
use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.
the class TcpDiscoverySharedFsIpFinder method name.
/**
* Creates file name for address.
*
* @param addr Node address.
* @return Name.
*/
private String name(InetSocketAddress addr) {
assert addr != null;
SB sb = new SB();
sb.a(normalizeAddress(addr.getAddress().getHostAddress())).a(DELIM).a(addr.getPort());
return sb.toString();
}
use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.
the class GridRestProcessor method handleRequest.
/**
* @param req Request.
* @return Future.
*/
private IgniteInternalFuture<GridRestResponse> handleRequest(final GridRestRequest req) {
if (startLatch.getCount() > 0) {
try {
startLatch.await();
} catch (InterruptedException e) {
return new GridFinishedFuture<>(new IgniteCheckedException("Failed to handle request " + "(protocol handler was interrupted when awaiting grid start).", e));
}
}
if (log.isDebugEnabled())
log.debug("Received request from client: " + req);
if (ctx.security().enabled()) {
Session ses;
try {
ses = session(req);
} catch (IgniteCheckedException e) {
GridRestResponse res = new GridRestResponse(STATUS_FAILED, e.getMessage());
return new GridFinishedFuture<>(res);
}
assert ses != null;
req.clientId(ses.clientId);
req.sessionToken(U.uuidToBytes(ses.sesId));
if (log.isDebugEnabled())
log.debug("Next clientId and sessionToken were extracted according to request: " + "[clientId=" + req.clientId() + ", sesTok=" + Arrays.toString(req.sessionToken()) + "]");
SecurityContext secCtx0 = ses.secCtx;
try {
if (secCtx0 == null)
ses.secCtx = secCtx0 = authenticate(req);
authorize(req, secCtx0);
} catch (SecurityException e) {
assert secCtx0 != null;
GridRestResponse res = new GridRestResponse(STATUS_SECURITY_CHECK_FAILED, e.getMessage());
return new GridFinishedFuture<>(res);
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(new GridRestResponse(STATUS_AUTH_FAILED, e.getMessage()));
}
}
interceptRequest(req);
GridRestCommandHandler hnd = handlers.get(req.command());
IgniteInternalFuture<GridRestResponse> res = hnd == null ? null : hnd.handleAsync(req);
if (res == null)
return new GridFinishedFuture<>(new IgniteCheckedException("Failed to find registered handler for command: " + req.command()));
return res.chain(new C1<IgniteInternalFuture<GridRestResponse>, GridRestResponse>() {
@Override
public GridRestResponse apply(IgniteInternalFuture<GridRestResponse> f) {
GridRestResponse res;
boolean failed = false;
try {
res = f.get();
} catch (Exception e) {
failed = true;
if (!X.hasCause(e, VisorClusterGroupEmptyException.class))
LT.error(log, e, "Failed to handle request: " + req.command());
if (log.isDebugEnabled())
log.debug("Failed to handle request [req=" + req + ", e=" + e + "]");
// Prepare error message:
SB sb = new SB(256);
sb.a("Failed to handle request: [req=").a(req.command());
if (req instanceof GridRestTaskRequest) {
GridRestTaskRequest tskReq = (GridRestTaskRequest) req;
sb.a(", taskName=").a(tskReq.taskName()).a(", params=").a(tskReq.params());
}
sb.a(", err=").a(e.getMessage() != null ? e.getMessage() : e.getClass().getName()).a(']');
res = new GridRestResponse(STATUS_FAILED, sb.toString());
}
assert res != null;
if (ctx.security().enabled() && !failed)
res.sessionTokenBytes(req.sessionToken());
interceptResponse(res, req);
return res;
}
});
}
Aggregations