Search in sources :

Example 61 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class AbstractAsterixListIterator method reset.

@Override
public void reset() throws HyracksDataException {
    count = 0;
    try {
        pos = getItemOffset(data, startOff, count);
        nextPos = startOff + listLength;
        if (count + 1 < numberOfItems) {
            nextPos = getItemOffset(data, startOff, count + 1);
        }
        itemLen = nextPos - pos;
    } catch (AsterixException e) {
        throw new HyracksDataException(e);
    }
}
Also used : AsterixException(org.apache.asterix.common.exceptions.AsterixException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 62 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class TwitterUtil method initializeConfigurationWithAuthInfo.

public static void initializeConfigurationWithAuthInfo(Map<String, String> configuration) throws AsterixException {
    String authMode = configuration.get(AuthenticationConstants.AUTHENTICATION_MODE);
    if (authMode == null) {
        authMode = AuthenticationConstants.AUTHENTICATION_MODE_FILE;
    }
    try {
        switch(authMode) {
            case AuthenticationConstants.AUTHENTICATION_MODE_FILE:
                Properties prop = new Properties();
                String authFile = configuration.get(AuthenticationConstants.OAUTH_AUTHENTICATION_FILE);
                if (authFile == null) {
                    authFile = AuthenticationConstants.DEFAULT_AUTH_FILE;
                }
                InputStream in = TwitterUtil.class.getResourceAsStream(authFile);
                prop.load(in);
                in.close();
                configuration.put(AuthenticationConstants.OAUTH_CONSUMER_KEY, prop.getProperty(AuthenticationConstants.OAUTH_CONSUMER_KEY));
                configuration.put(AuthenticationConstants.OAUTH_CONSUMER_SECRET, prop.getProperty(AuthenticationConstants.OAUTH_CONSUMER_SECRET));
                configuration.put(AuthenticationConstants.OAUTH_ACCESS_TOKEN, prop.getProperty(AuthenticationConstants.OAUTH_ACCESS_TOKEN));
                configuration.put(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET, prop.getProperty(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET));
                break;
            case AuthenticationConstants.AUTHENTICATION_MODE_EXPLICIT:
                break;
        }
    } catch (Exception e) {
        if (LOGGER.isLoggable(Level.WARNING)) {
            LOGGER.warning("unable to load authentication credentials from auth.properties file" + "credential information will be obtained from adapter's configuration");
        }
    }
}
Also used : InputStream(java.io.InputStream) Properties(java.util.Properties) AsterixException(org.apache.asterix.common.exceptions.AsterixException)

Example 63 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class TwitterUtil method getBoundingBoxes.

/**
     * Gets more than one bounding box from a sequences of coordinates
     * (following Twitter formats) + predefined location names, as US and EU.
     * E.g., for EU and US, we would use -29.7, 79.2, 36.7, 72.0; -124.848974,
     * -66.885444, 24.396308, 49.384358.
     *
     * @param locationValue
     *            String value of the location coordinates or names (comma-separated)
     * @return
     * @throws AsterixException
     */
public static double[][] getBoundingBoxes(String locationValue) throws AsterixException {
    double[][] locations = null;
    String coordRegex = "^((((\\-?\\d+\\.\\d+),\\s*){3}(\\-?\\d+\\.\\d+)|\\w+);\\s*)*(((\\-?\\d+\\.\\d+),\\s*){3}(\\-?\\d+\\.\\d+)|\\w+)$";
    Pattern p = Pattern.compile(coordRegex);
    Matcher m = p.matcher(locationValue);
    if (m.matches()) {
        String[] locationStrings = locationValue.trim().split(";\\s*");
        locations = new double[locationStrings.length * 2][2];
        for (int i = 0; i < locationStrings.length; i++) {
            if (locationStrings[i].contains(",")) {
                String[] coordinatesString = locationStrings[i].split(",");
                for (int k = 0; k < 2; k++) {
                    for (int l = 0; l < 2; l++) {
                        try {
                            locations[2 * i + k][l] = Double.parseDouble(coordinatesString[2 * k + l]);
                        } catch (NumberFormatException ne) {
                            throw new AsterixException("Incorrect coordinate value " + coordinatesString[2 * k + l]);
                        }
                    }
                }
            } else if (GeoConstants.boundingBoxes.containsKey(locationStrings[i])) {
                // Only add known locations
                double[][] loc = GeoConstants.boundingBoxes.get(locationStrings[i]);
                for (int k = 0; k < 2; k++) {
                    for (int l = 0; l < 2; l++) {
                        locations[2 * i + k][l] = loc[k][l];
                    }
                }
            }
        }
    }
    return locations;
}
Also used : Pattern(java.util.regex.Pattern) AsterixException(org.apache.asterix.common.exceptions.AsterixException) Matcher(java.util.regex.Matcher)

Example 64 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class ClusterManager method addNode.

@Override
public void addNode(ICcApplicationContext appCtx, Node node) throws AsterixException {
    try {
        Cluster cluster = ClusterProperties.INSTANCE.getCluster();
        List<Pattern> pattern = new ArrayList<>();
        String asterixInstanceName = appCtx.getMetadataProperties().getInstanceName();
        Patterns prepareNode = PatternCreator.INSTANCE.createPrepareNodePattern(asterixInstanceName, ClusterProperties.INSTANCE.getCluster(), node);
        cluster.getNode().add(node);
        client.submit(prepareNode);
        ExternalProperties externalProps = appCtx.getExternalProperties();
        AsterixEventServiceUtil.poulateClusterEnvironmentProperties(cluster, externalProps.getCCJavaParams(), externalProps.getNCJavaParams());
        pattern.clear();
        String ccHost = cluster.getMasterNode().getClusterIp();
        String hostId = node.getId();
        String nodeControllerId = asterixInstanceName + "_" + node.getId();
        String iodevices = node.getIodevices() == null ? cluster.getIodevices() : node.getIodevices();
        Pattern startNC = PatternCreator.INSTANCE.createNCStartPattern(ccHost, hostId, nodeControllerId, iodevices, false);
        pattern.add(startNC);
        Patterns startNCPattern = new Patterns(pattern);
        client.submit(startNCPattern);
        removeNode(cluster.getSubstituteNodes().getNode(), node);
        AsterixInstance instance = lookupService.getAsterixInstance(cluster.getInstanceName());
        instance.getCluster().getNode().add(node);
        removeNode(instance.getCluster().getSubstituteNodes().getNode(), node);
        lookupService.updateAsterixInstance(instance);
    } catch (Exception e) {
        throw new AsterixException(e);
    }
}
Also used : Pattern(org.apache.asterix.event.schema.pattern.Pattern) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ArrayList(java.util.ArrayList) ExternalProperties(org.apache.asterix.common.config.ExternalProperties) Cluster(org.apache.asterix.event.schema.cluster.Cluster) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Patterns(org.apache.asterix.event.schema.pattern.Patterns) AsterixException(org.apache.asterix.common.exceptions.AsterixException)

Example 65 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class AsterixProperties method registerConfigOptions.

public static void registerConfigOptions(IConfigManager configManager) {
    configManager.register(NodeProperties.Option.class, CompilerProperties.Option.class, MetadataProperties.Option.class, ExternalProperties.Option.class, ActiveProperties.Option.class, MessagingProperties.Option.class, ReplicationProperties.Option.class, StorageProperties.Option.class, TransactionProperties.Option.class);
    // we need to process the old-style asterix config before we apply defaults!
    configManager.addConfigurator(IConfigManager.ConfiguratorMetric.APPLY_DEFAULTS.metric() - 1, () -> {
        try {
            PropertiesAccessor.getInstance(configManager.getAppConfig());
        } catch (AsterixException e) {
            throw new HyracksDataException(e);
        }
    });
}
Also used : AsterixException(org.apache.asterix.common.exceptions.AsterixException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

AsterixException (org.apache.asterix.common.exceptions.AsterixException)67 IOException (java.io.IOException)27 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)26 DataOutput (java.io.DataOutput)15 IPointable (org.apache.hyracks.data.std.api.IPointable)15 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)15 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)14 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)14 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)14 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)14 ATypeTag (org.apache.asterix.om.types.ATypeTag)10 IAType (org.apache.asterix.om.types.IAType)10 ARecordType (org.apache.asterix.om.types.ARecordType)9 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)9 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)9 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)8 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)8 List (java.util.List)7 InputStream (java.io.InputStream)5 CompilationException (org.apache.asterix.common.exceptions.CompilationException)5