Search in sources :

Example 1 with Variable

use of com.teradata.jaqy.interfaces.Variable in project jaqy by Teradata.

the class S3Utils method getS3Builder.

public static AmazonS3ClientBuilder getS3Builder(JaqyInterpreter interpreter) {
    VariableManager vm = interpreter.getVariableManager();
    Variable var = vm.getVariable(S3BUILDER_VAR);
    if (var != null) {
        Object o = var.get();
        if (o instanceof AmazonS3ClientBuilder)
            return (AmazonS3ClientBuilder) o;
    }
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
    builder.withPathStyleAccessEnabled(true);
    vm.setVariable(S3BUILDER_VAR, builder);
    return builder;
}
Also used : VariableManager(com.teradata.jaqy.VariableManager) Variable(com.teradata.jaqy.interfaces.Variable) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder)

Example 2 with Variable

use of com.teradata.jaqy.interfaces.Variable in project jaqy by Teradata.

the class ClientRSUtils method getSortNull.

public static boolean getSortNull(JaqyInterpreter interpreter) {
    VariableManager vm = interpreter.getVariableManager();
    Variable var = vm.getVariable(NULLSORT_VAR);
    if (var == null) {
        vm.setVariable(NULLSORT_VAR, DEFAULT_NULLSORT_VALUE);
        return DEFAULT_NULLSORT_VALUE;
    }
    Object v = var.get();
    if (v instanceof Boolean) {
        return ((Boolean) v).booleanValue();
    }
    return DEFAULT_NULLSORT_VALUE;
}
Also used : VariableManager(com.teradata.jaqy.VariableManager) Variable(com.teradata.jaqy.interfaces.Variable)

Example 3 with Variable

use of com.teradata.jaqy.interfaces.Variable in project jaqy by Teradata.

the class VariableManager method setVariable.

public Object setVariable(String name, Object value) {
    if (name == null || name.length() == 0) {
        throw new IllegalArgumentException("Empty variable name.");
    }
    if (value instanceof Variable) {
        setVariable((Variable) value);
        return null;
    }
    if (m_parent != null && m_parent.containsKey(name)) {
        return m_parent.setVariable(name, value);
    }
    Variable var;
    synchronized (m_lock) {
        var = (Variable) m_variables.get(name);
        if (var == null) {
            var = new SimpleVariable(name);
            var.set(value);
            m_variables.put(name, var);
            return null;
        }
    }
    Object old = var.get();
    if (!var.set(value)) {
        throw new IllegalArgumentException("Cannot set the variable: " + name);
    }
    return old;
}
Also used : Variable(com.teradata.jaqy.interfaces.Variable) SimpleVariable(com.teradata.jaqy.utils.SimpleVariable) FixedVariable(com.teradata.jaqy.utils.FixedVariable) SimpleVariable(com.teradata.jaqy.utils.SimpleVariable)

Example 4 with Variable

use of com.teradata.jaqy.interfaces.Variable in project jaqy by Teradata.

the class TimerCommand method getStartTime.

private long getStartTime(JaqyInterpreter interpreter) {
    VariableManager vm = interpreter.getVariableManager();
    Variable var = vm.getVariable("timer");
    if (var == null)
        return 0;
    Object o = var.get();
    if (o == null)
        return 0;
    if (!(o instanceof Number))
        return 0;
    return ((Number) o).longValue();
}
Also used : VariableManager(com.teradata.jaqy.VariableManager) Variable(com.teradata.jaqy.interfaces.Variable)

Example 5 with Variable

use of com.teradata.jaqy.interfaces.Variable in project jaqy by Teradata.

the class S3Utils method getS3Client.

public static AmazonS3 getS3Client(JaqyInterpreter interpreter) {
    VariableManager vm = interpreter.getVariableManager();
    Variable clientVar = vm.getVariable(S3CLIENT_VAR);
    if (clientVar != null) {
        Object o = clientVar.get();
        if (o instanceof AmazonS3)
            return (AmazonS3) o;
    }
    // now we need to setup a new client.
    AmazonS3ClientBuilder builder = getS3Builder(interpreter);
    // check if we need to set up the access / secret key
    String access = null;
    String secret = null;
    {
        Variable var = vm.getVariable(S3ACCESS_VAR);
        if (var != null) {
            Object o = var.get();
            if (o != null)
                access = o.toString();
        }
    }
    {
        Variable var = vm.getVariable(S3SECRET_VAR);
        if (var != null) {
            Object o = var.get();
            if (o != null)
                secret = o.toString();
        }
    }
    if (access != null && secret != null) {
        /*
			 * When both access and secret are null, we are using the default
			 * values (i.e. from credential file or env variables etc).
			 * 
			 * When both are set, then we override the default settings (and
			 * subsequent uses).
			 */
        if (access.length() == 0 && secret.length() == 0) {
            /*
				 * This is for accessing publicly accessible buckets.
				 */
            builder.withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()));
        } else {
            builder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(access, secret)));
        }
    }
    AmazonS3 client = builder.build();
    // now save the client to s3client variable
    if (clientVar == null) {
        clientVar = new Variable() {

            private AmazonS3 m_client;

            @Override
            public Object get() {
                return m_client;
            }

            @Override
            public boolean set(Object value) {
                if (value != null && !(value instanceof AmazonS3))
                    return false;
                m_client = (AmazonS3) value;
                return true;
            }

            @Override
            public String getName() {
                return S3CLIENT_VAR;
            }
        };
    }
    clientVar.set(client);
    vm.setVariable(clientVar);
    return client;
}
Also used : VariableManager(com.teradata.jaqy.VariableManager) AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) Variable(com.teradata.jaqy.interfaces.Variable) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

Variable (com.teradata.jaqy.interfaces.Variable)5 VariableManager (com.teradata.jaqy.VariableManager)4 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 FixedVariable (com.teradata.jaqy.utils.FixedVariable)1 SimpleVariable (com.teradata.jaqy.utils.SimpleVariable)1