Search in sources :

Example 21 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class VisorTaskUtils method formatDuration.

/**
     * Pretty-formatting for duration.
     *
     * @param ms Millisecond to format.
     * @return Formatted presentation.
     */
private static String formatDuration(long ms) {
    assert ms >= 0;
    if (ms == 0)
        return "< 1 ms";
    SB sb = new SB();
    // 1440 mins = 60 mins * 24 hours
    long dd = ms / 1440000;
    if (dd > 0)
        sb.a(dd).a(dd == 1 ? " day " : " days ");
    ms %= 1440000;
    long hh = ms / 60000;
    if (hh > 0)
        sb.a(hh).a(hh == 1 ? " hour " : " hours ");
    long min = ms / 60000;
    if (min > 0)
        sb.a(min).a(min == 1 ? " min " : " mins ");
    ms %= 60000;
    if (ms > 0)
        sb.a(ms).a(" ms ");
    return sb.toString().trim();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 22 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class IgniteSpiAdapter method checkConfigurationConsistency.

/**
     * Checks remote node SPI configuration and prints warnings if necessary.
     *
     * @param spiCtx SPI context.
     * @param node Remote node.
     * @param starting Flag indicating whether this method is called during SPI start or not.
     * @throws IgniteSpiException If check fatally failed.
     */
@SuppressWarnings("IfMayBeConditional")
private void checkConfigurationConsistency(IgniteSpiContext spiCtx, ClusterNode node, boolean starting) throws IgniteSpiException {
    assert spiCtx != null;
    assert node != null;
    /*
         * Optional SPI means that we should not print warning if SPIs are different but
         * still need to compare attributes if SPIs are the same.
         */
    boolean optional = checkOptional();
    boolean enabled = checkEnabled();
    boolean checkClient = checkClient();
    if (!enabled)
        return;
    if (!checkClient && (CU.clientNode(getLocalNode()) || CU.clientNode(node)))
        return;
    String clsAttr = createSpiAttributeName(IgniteNodeAttributes.ATTR_SPI_CLASS);
    String name = getName();
    SB sb = new SB();
    /*
         * If there are any attributes do compare class and version
         * (do not print warning for the optional SPIs).
         */
    /* Check SPI class and version. */
    String locCls = spiCtx.localNode().attribute(clsAttr);
    String rmtCls = node.attribute(clsAttr);
    assert locCls != null : "Local SPI class name attribute not found: " + clsAttr;
    boolean isSpiConsistent = false;
    String tipStr = " (fix configuration or set " + "-D" + IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK + "=true system property)";
    if (rmtCls == null) {
        if (!optional && starting)
            throw new IgniteSpiException("Remote SPI with the same name is not configured" + tipStr + " [name=" + name + ", loc=" + locCls + ']');
        sb.a(format(">>> Remote SPI with the same name is not configured: " + name, locCls));
    } else if (!locCls.equals(rmtCls)) {
        if (!optional && starting)
            throw new IgniteSpiException("Remote SPI with the same name is of different type" + tipStr + " [name=" + name + ", loc=" + locCls + ", rmt=" + rmtCls + ']');
        sb.a(format(">>> Remote SPI with the same name is of different type: " + name, locCls, rmtCls));
    } else
        isSpiConsistent = true;
    if (optional && !isSpiConsistent)
        return;
    // It makes no sense to compare inconsistent SPIs attributes.
    if (isSpiConsistent) {
        List<String> attrs = getConsistentAttributeNames();
        // Process all SPI specific attributes.
        for (String attr : attrs) {
            // Ignore class and version attributes processed above.
            if (!attr.equals(clsAttr)) {
                // This check is considered as optional if no attributes
                Object rmtVal = node.attribute(attr);
                Object locVal = spiCtx.localNode().attribute(attr);
                if (locVal == null && rmtVal == null)
                    continue;
                if (locVal == null || rmtVal == null || !locVal.equals(rmtVal))
                    sb.a(format(">>> Remote node has different " + getName() + " SPI attribute " + attr, locVal, rmtVal));
            }
        }
    }
    if (sb.length() > 0) {
        String msg;
        if (starting)
            msg = U.nl() + U.nl() + ">>> +--------------------------------------------------------------------+" + U.nl() + ">>> + Courtesy notice that starting node has inconsistent configuration. +" + U.nl() + ">>> + Ignore this message if you are sure that this is done on purpose.  +" + U.nl() + ">>> +--------------------------------------------------------------------+" + U.nl() + ">>> Remote Node ID: " + node.id().toString().toUpperCase() + U.nl() + sb;
        else
            msg = U.nl() + U.nl() + ">>> +-------------------------------------------------------------------+" + U.nl() + ">>> + Courtesy notice that joining node has inconsistent configuration. +" + U.nl() + ">>> + Ignore this message if you are sure that this is done on purpose. +" + U.nl() + ">>> +-------------------------------------------------------------------+" + U.nl() + ">>> Remote Node ID: " + node.id().toString().toUpperCase() + U.nl() + sb;
        U.courtesy(log, msg);
    }
}
Also used : GridSpiTimeoutObject(org.apache.ignite.internal.processors.timeout.GridSpiTimeoutObject) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 23 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class H2IndexingAbstractGeoSelfTest method createDynamicIndex.

/**
     * Create dynamic index.
     *
     * @param cache Cache.
     * @param entity Entity.
     * @param idx Index.
     * @throws Exception If failed.
     */
private void createDynamicIndex(IgniteCache cache, QueryEntity entity, QueryIndex idx) throws Exception {
    boolean spatial = idx.getIndexType() == QueryIndexType.GEOSPATIAL;
    GridStringBuilder sb = new SB("CREATE ").a(spatial ? "SPATIAL " : "").a("INDEX ").a("\"" + idx.getName() + "\"").a(" ON ").a(QueryUtils.tableName(entity)).a(" (");
    boolean first = true;
    for (Map.Entry<String, Boolean> fieldEntry : idx.getFields().entrySet()) {
        if (first)
            first = false;
        else
            sb.a(", ");
        String name = fieldEntry.getKey();
        boolean asc = fieldEntry.getValue();
        sb.a("\"" + name + "\"").a(" ").a(asc ? "ASC" : "DESC");
    }
    sb.a(')');
    String sql = sb.toString();
    cache.query(new SqlFieldsQuery(sql)).getAll();
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Map(java.util.Map) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 24 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class HadoopJobTracker method printPlan.

/**
     * @param jobId  Job ID.
     * @param plan Map-reduce plan.
     */
@SuppressWarnings({ "unused", "ConstantConditions" })
private void printPlan(HadoopJobId jobId, HadoopMapReducePlan plan) {
    log.info("Plan for " + jobId);
    SB b = new SB();
    b.a("   Map: ");
    for (UUID nodeId : plan.mapperNodeIds()) b.a(nodeId).a("=").a(plan.mappers(nodeId).size()).a(' ');
    log.info(b.toString());
    b = new SB();
    b.a("   Reduce: ");
    for (UUID nodeId : plan.reducerNodeIds()) b.a(nodeId).a("=").a(Arrays.toString(plan.reducers(nodeId))).a(' ');
    log.info(b.toString());
}
Also used : UUID(java.util.UUID) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 25 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class GridQueryParsingTest method createTableToSql.

/**
     * @param createTbl {@code CREATE TABLE} command.
     * @return Corresponding SQL.
     */
private static String createTableToSql(GridSqlCreateTable createTbl) {
    GridStringBuilder b = new SB("CREATE TABLE ").a(createTbl.ifNotExists() ? "IF NOT EXISTS " : "").a("\n").a(Parser.quoteIdentifier(createTbl.schemaName())).a('.').a(Parser.quoteIdentifier(createTbl.tableName())).a("\n(");
    boolean singleColPk = false;
    boolean first = true;
    for (GridSqlColumn col : createTbl.columns().values()) {
        if (!first)
            b.a(",\n");
        else
            first = false;
        if (col.column().isPrimaryKey()) {
            // Only one column may be marked PRIMARY KEY - multi-col PK is defined separately
            assert !singleColPk;
            singleColPk = true;
        }
        b.a('\t').a(col.getSQL()).a(' ').a(col.resultType().sql()).a(col.column().isPrimaryKey() ? " PRIMARY KEY" : "");
    }
    first = true;
    if (!singleColPk && !F.isEmpty(createTbl.primaryKeyColumns())) {
        b.a(",\n").a('\t').a("PRIMARY KEY (\n");
        for (String col : createTbl.primaryKeyColumns()) {
            GridSqlColumn pkCol = createTbl.columns().get(col);
            assert pkCol != null;
            if (!first)
                b.a(",\n");
            else
                first = false;
            b.a("\t\t").a(pkCol.getSQL());
        }
        b.a("\n\t)");
    }
    b.a("\n)");
    if (!F.isEmpty(createTbl.params())) {
        b.a("\nWITH ");
        first = true;
        for (String p : createTbl.params()) {
            if (!first)
                b.a(',');
            else
                first = false;
            b.a(Parser.quoteIdentifier(p));
        }
    }
    return b.toString();
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

SB (org.apache.ignite.internal.util.typedef.internal.SB)57 Map (java.util.Map)8 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)4 IgfsLogger (org.apache.ignite.internal.igfs.common.IgfsLogger)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 LineNumberReader (java.io.LineNumberReader)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ObjectName (javax.management.ObjectName)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2