Github user cestella commented on a diff in the pull request: https://github.com/apache/incubator-metron/pull/242#discussion_r78433046 --- Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/GetProfile.java --- @@ -0,0 +1,179 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.metron.profiler.client.stellar; + +import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.hbase.client.HTableInterface; +import org.apache.metron.common.dsl.Context; +import org.apache.metron.common.dsl.ParseException; +import org.apache.metron.common.dsl.Stellar; +import org.apache.metron.common.dsl.StellarFunction; +import org.apache.metron.common.utils.ConversionUtils; +import org.apache.metron.profiler.client.HBaseProfilerClient; +import org.apache.metron.profiler.client.ProfilerClient; +import org.apache.metron.profiler.hbase.ColumnBuilder; +import org.apache.metron.profiler.hbase.RowKeyBuilder; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.lang.String.format; +import static org.apache.metron.common.dsl.Context.Capabilities.PROFILER_COLUMN_BUILDER; +import static org.apache.metron.common.dsl.Context.Capabilities.PROFILER_HBASE_TABLE; +import static org.apache.metron.common.dsl.Context.Capabilities.PROFILER_ROW_KEY_BUILDER; + +/** + * A Stellar function that can retrieve data contained within a Profile. + * + * PROFILE_GET + * + * Retrieve all values for 'entity1' from 'profile1' over the past 4 hours. + * + * <code>PROFILE_GET('profile1', 'entity1', 4, 'HOURS')</code> + * + * Retrieve all values for 'entity1' from 'profile1' over the past 2 days. + * + * <code>PROFILE_GET('profile1', 'entity1', 2, 'DAYS')</code> + * + * Retrieve all values for 'entity1' from 'profile1' that occurred on 'weekdays' over the past month. + * + * <code>PROFILE_GET('profile1', 'entity1', 1, 'MONTHS', 'weekdays')</code> + * + */ +@Stellar( + namespace="PROFILE", + name="GET", + description="Retrieves a series of values from a stored profile.", + params={ + "profile - The name of the profile.", + "entity - The name of the entity.", + "durationAgo - How long ago should values be retrieved from?", + "units - The units of 'durationAgo'.", + "groups - Optional - The groups used to sort the profile." + }, + returns="The profile measurements." +) +public class GetProfile implements StellarFunction { + + private ProfilerClient client; + + /** + * Initialization. + */ + @Override + public void initialize(Context context) { + + Context.Capabilities[] required = { PROFILER_HBASE_TABLE, PROFILER_ROW_KEY_BUILDER, PROFILER_COLUMN_BUILDER }; + validateContext(context, required); + + HTableInterface table = (HTableInterface) context.getCapability(PROFILER_HBASE_TABLE).get(); + RowKeyBuilder rowKeyBuilder = (RowKeyBuilder) context.getCapability(PROFILER_ROW_KEY_BUILDER).get(); + ColumnBuilder columnBuilder = (ColumnBuilder) context.getCapability(PROFILER_COLUMN_BUILDER).get(); + + client = new HBaseProfilerClient(table, rowKeyBuilder, columnBuilder); + } + + /** + * Is the function initialized? + */ + @Override + public boolean isInitialized() { + return client != null; + } + + /** + * Apply the function. + * @param args The function arguments. + * @param context + */ + @Override + public Object apply(List<Object> args, Context context) throws ParseException { + + String profile = getArg(0, String.class, args); + String entity = getArg(1, String.class, args); + long durationAgo = getArg(2, Long.class, args); + String unitsName = getArg(3, String.class, args); + TimeUnit units = TimeUnit.valueOf(unitsName); + List<Object> groups = getGroupsArg(4, args); + + return client.fetch(profile, entity, durationAgo, units, Integer.class, groups); --- End diff -- What is hard coded as an integer? The argument index (e.g. `getArg(i, ...)`)?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---