use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.
the class QueryTranslatorTest method test.
@Test
public void test() throws Exception {
List<Statement> statements = new ArrayList<>();
SessionOutput mockSessionOutput = mock(SessionOutput.class);
RunStatement mockRunStatement = mock(RunStatement.class);
// Mocks AppContextInfo.
CcApplicationContext mockAsterixAppContextInfo = mock(CcApplicationContext.class);
ExternalProperties mockAsterixExternalProperties = mock(ExternalProperties.class);
when(mockAsterixAppContextInfo.getExternalProperties()).thenReturn(mockAsterixExternalProperties);
when(mockAsterixExternalProperties.getAPIServerPort()).thenReturn(19002);
// Mocks AsterixClusterProperties.
Cluster mockCluster = mock(Cluster.class);
MasterNode mockMasterNode = mock(MasterNode.class);
ClusterProperties mockClusterProperties = mock(ClusterProperties.class);
setFinalStaticField(ClusterProperties.class.getDeclaredField("INSTANCE"), mockClusterProperties);
when(mockClusterProperties.getCluster()).thenReturn(mockCluster);
when(mockCluster.getMasterNode()).thenReturn(mockMasterNode);
when(mockMasterNode.getClientIp()).thenReturn("127.0.0.1");
IStatementExecutor aqlTranslator = new DefaultStatementExecutorFactory().create(mockAsterixAppContextInfo, statements, mockSessionOutput, new AqlCompilationProvider(), new StorageComponentProvider());
List<String> parameters = new ArrayList<>();
parameters.add("examples/pregelix-example-jar-with-dependencies.jar");
parameters.add("org.apache.pregelix.example.PageRankVertex");
parameters.add("-ip 10.0.2.15 -port 3199");
when(mockRunStatement.getParameters()).thenReturn(parameters);
// Test a customer command without "-cust-prop".
List<String> cmds = (List<String>) PA.invokeMethod(aqlTranslator, "constructPregelixCommand(org.apache.asterix.lang.common.statement.RunStatement," + "String,String,String,String)", mockRunStatement, "fromDataverse", "fromDataset", "toDataverse", "toDataset");
List<String> expectedCmds = Arrays.asList(new String[] { "bin/pregelix", "examples/pregelix-example-jar-with-dependencies.jar", "org.apache.pregelix.example.PageRankVertex", "-ip", "10.0.2.15", "-port", "3199", "-cust-prop", "pregelix.asterixdb.url=http://127.0.0.1:19002,pregelix.asterixdb.source=true,pregelix.asterixdb.sink=true,pregelix.asterixdb.input.dataverse=fromDataverse,pregelix.asterixdb.input.dataset=fromDataset,pregelix.asterixdb.output.dataverse=toDataverse,pregelix.asterixdb.output.dataset=toDataset,pregelix.asterixdb.output.cleanup=false,pregelix.asterixdb.input.converterclass=org.apache.pregelix.example.converter.VLongIdInputVertexConverter,pregelix.asterixdb.output.converterclass=org.apache.pregelix.example.converter.VLongIdOutputVertexConverter" });
Assert.assertEquals(cmds, expectedCmds);
parameters.remove(parameters.size() - 1);
parameters.add("-ip 10.0.2.15 -port 3199 -cust-prop " + "pregelix.asterixdb.input.converterclass=org.apache.pregelix.example.converter.TestInputVertexConverter," + "pregelix.asterixdb.output.converterclass=org.apache.pregelix.example.converter.TestOutputVertexConverter");
// Test a customer command with "-cust-prop".
cmds = (List<String>) PA.invokeMethod(aqlTranslator, "constructPregelixCommand(org.apache.asterix.lang.common.statement.RunStatement," + "String,String,String,String)", mockRunStatement, "fromDataverse", "fromDataset", "toDataverse", "toDataset");
expectedCmds = Arrays.asList(new String[] { "bin/pregelix", "examples/pregelix-example-jar-with-dependencies.jar", "org.apache.pregelix.example.PageRankVertex", "-ip", "10.0.2.15", "-port", "3199", "-cust-prop", "pregelix.asterixdb.url=http://127.0.0.1:19002,pregelix.asterixdb.source=true,pregelix.asterixdb.sink=true,pregelix.asterixdb.input.dataverse=fromDataverse,pregelix.asterixdb.input.dataset=fromDataset,pregelix.asterixdb.output.dataverse=toDataverse,pregelix.asterixdb.output.dataset=toDataset,pregelix.asterixdb.output.cleanup=false,pregelix.asterixdb.input.converterclass=org.apache.pregelix.example.converter.TestInputVertexConverter,pregelix.asterixdb.output.converterclass=org.apache.pregelix.example.converter.TestOutputVertexConverter" });
Assert.assertEquals(cmds, expectedCmds);
}
use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.
the class CCApplication method start.
@Override
public void start(IServiceContext serviceCtx, String[] args) throws Exception {
if (args.length > 0) {
throw new IllegalArgumentException("Unrecognized argument(s): " + Arrays.toString(args));
}
final ClusterControllerService controllerService = (ClusterControllerService) serviceCtx.getControllerService();
this.ccServiceCtx = (ICCServiceContext) serviceCtx;
ccServiceCtx.setMessageBroker(new CCMessageBroker(controllerService));
configureLoggingLevel(ccServiceCtx.getAppConfig().getLoggingLevel(ExternalProperties.Option.LOG_LEVEL));
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Starting Asterix cluster controller");
}
ccServiceCtx.setThreadFactory(new AsterixThreadFactory(ccServiceCtx.getThreadFactory(), new LifeCycleComponentManager()));
ILibraryManager libraryManager = new ExternalLibraryManager();
ResourceIdManager resourceIdManager = new ResourceIdManager();
IReplicationStrategy repStrategy = ClusterProperties.INSTANCE.getReplicationStrategy();
IFaultToleranceStrategy ftStrategy = FaultToleranceStrategyFactory.create(ClusterProperties.INSTANCE.getCluster(), repStrategy, ccServiceCtx);
ExternalLibraryUtils.setUpExternaLibraries(libraryManager, false);
componentProvider = new StorageComponentProvider();
GlobalRecoveryManager.instantiate(ccServiceCtx, getHcc(), componentProvider);
statementExecutorCtx = new StatementExecutorContext();
appCtx = new CcApplicationContext(ccServiceCtx, getHcc(), libraryManager, resourceIdManager, () -> MetadataManager.INSTANCE, GlobalRecoveryManager.instance(), ftStrategy, new ActiveLifecycleListener(), componentProvider);
ClusterStateManager.INSTANCE.setCcAppCtx(appCtx);
ccExtensionManager = new CCExtensionManager(getExtensions());
appCtx.setExtensionManager(ccExtensionManager);
final CCConfig ccConfig = controllerService.getCCConfig();
if (System.getProperty("java.rmi.server.hostname") == null) {
System.setProperty("java.rmi.server.hostname", ccConfig.getClusterListenAddress());
}
MetadataProperties metadataProperties = appCtx.getMetadataProperties();
setAsterixStateProxy(AsterixStateProxy.registerRemoteObject(metadataProperties.getMetadataCallbackPort()));
ccServiceCtx.setDistributedState(proxy);
MetadataManager.initialize(proxy, metadataProperties);
ccServiceCtx.addJobLifecycleListener(appCtx.getActiveLifecycleListener());
// create event loop groups
webManager = new WebManager();
configureServers();
webManager.start();
ClusterManagerProvider.getClusterManager().registerSubscriber(GlobalRecoveryManager.instance());
ccServiceCtx.addClusterLifecycleListener(new ClusterLifecycleListener(appCtx));
jobCapacityController = new JobCapacityController(controllerService.getResourceManager());
}
use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.
the class ClusterApiServlet method getClusterStateJSON.
protected ObjectNode getClusterStateJSON(IServletRequest request, String pathToNode) {
ObjectNode json = ClusterStateManager.INSTANCE.getClusterStateDescription();
CcApplicationContext appConfig = (CcApplicationContext) ctx.get(ASTERIX_APP_CONTEXT_INFO_ATTR);
json.putPOJO("config", ConfigUtils.getSectionOptionsForJSON(appConfig.getServiceContext().getAppConfig(), Section.COMMON, getConfigSelector()));
ArrayNode ncs = (ArrayNode) json.get("ncs");
final StringBuilder requestURL = new StringBuilder("http://");
requestURL.append(request.getHeader(HttpHeaderNames.HOST));
requestURL.append(request.getHttpRequest().uri());
if (requestURL.charAt(requestURL.length() - 1) != '/') {
requestURL.append('/');
}
requestURL.append(pathToNode);
String clusterURL = canonicalize(requestURL);
String adminURL = canonicalize(clusterURL + "../");
String nodeURL = clusterURL + "node/";
for (int i = 0; i < ncs.size(); i++) {
ObjectNode nc = (ObjectNode) ncs.get(i);
nc.put(CONFIG_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/config");
nc.put(STATS_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/stats");
nc.put(THREAD_DUMP_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/threaddump");
}
ObjectNode cc;
if (json.has("cc")) {
cc = (ObjectNode) json.get("cc");
} else {
cc = om.createObjectNode();
json.set("cc", cc);
}
cc.put(CONFIG_URI_KEY, clusterURL + "cc/config");
cc.put(STATS_URI_KEY, clusterURL + "cc/stats");
cc.put(THREAD_DUMP_URI_KEY, clusterURL + "cc/threaddump");
json.put(SHUTDOWN_URI_KEY, adminURL + "shutdown");
json.put(FULL_SHUTDOWN_URI_KEY, adminURL + "shutdown?all=true");
json.put(VERSION_URI_KEY, adminURL + "version");
json.put(DIAGNOSTICS_URI_KEY, adminURL + "diagnostics");
return json;
}
use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.
the class VersionApiServletTest method testGet.
@Test
public void testGet() throws Exception {
// Configures a test version api servlet.
VersionApiServlet servlet = new VersionApiServlet(new ConcurrentHashMap<>(), new String[] { "/" });
Map<String, String> propMap = new HashMap<>();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintWriter outputWriter = new PrintWriter(outputStream);
// Creates mocks.
CcApplicationContext mockCtx = mock(CcApplicationContext.class);
IServletRequest mockRequest = mock(IServletRequest.class);
IHyracksClientConnection mockHcc = mock(IHyracksClientConnection.class);
IServletResponse mockResponse = mock(IServletResponse.class);
BuildProperties mockProperties = mock(BuildProperties.class);
FullHttpRequest mockHttpRequest = mock(FullHttpRequest.class);
// Put stuff in let map
servlet.ctx().put(HYRACKS_CONNECTION_ATTR, mockHcc);
servlet.ctx().put(ASTERIX_APP_CONTEXT_INFO_ATTR, mockCtx);
// Sets up mock returns.
when(mockResponse.writer()).thenReturn(outputWriter);
when(mockRequest.getHttpRequest()).thenReturn(mockHttpRequest);
when(mockHttpRequest.method()).thenReturn(HttpMethod.GET);
when(mockCtx.getBuildProperties()).thenReturn(mockProperties);
when(mockProperties.getAllProps()).thenReturn(propMap);
propMap.put("git.build.user.email", "foo@bar.baz");
propMap.put("git.build.host", "fulliautomatix");
propMap.put("git.dirty", "true");
propMap.put("git.remote.origin.url", "git@github.com:apache/incubator-asterixdb.git");
propMap.put("git.closest.tag.name", "asterix-0.8.7-incubating");
propMap.put("git.commit.id.describe-short", "asterix-0.8.7-incubating-19-dirty");
propMap.put("git.commit.user.email", "foo@bar.baz");
propMap.put("git.commit.time", "21.10.2015 @ 23:36:41 PDT");
propMap.put("git.commit.message.full", "ASTERIXDB-1045: fix log file reading during recovery\n\nChange-Id: Ic83ee1dd2d7ba88180c25f4ec6c7aa8d0a5a7162\nReviewed-on: https://asterix-gerrit.ics.uci.edu/465\nTested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>");
propMap.put("git.build.version", "0.8.8-SNAPSHOT");
propMap.put("git.commit.message.short", "ASTERIXDB-1045: fix log file reading during recovery");
propMap.put("git.commit.id.abbrev", "e1dad19");
propMap.put("git.branch", "foo/bar");
propMap.put("git.build.user.name", "Asterix");
propMap.put("git.closest.tag.commit.count", "19");
propMap.put("git.commit.id.describe", "asterix-0.8.7-incubating-19-ge1dad19-dirty");
propMap.put("git.commit.id", "e1dad1984640517366a7e73e323c9de27b0676f7");
propMap.put("git.tags", "");
propMap.put("git.build.time", "22.10.2015 @ 17:11:07 PDT");
propMap.put("git.commit.user.name", "Obelix");
// Calls VersionAPIServlet.formResponseObject.
servlet.handle(mockRequest, mockResponse);
// Constructs the actual response.
ObjectMapper om = new ObjectMapper();
ObjectNode actualResponse = (ObjectNode) om.readTree(outputStream.toByteArray());
ObjectNode expectedResponse = om.createObjectNode();
for (Map.Entry<String, String> e : propMap.entrySet()) {
expectedResponse.put(e.getKey(), e.getValue());
}
// Checks the response contains all the expected keys.
Assert.assertEquals(actualResponse.toString(), expectedResponse.toString());
}
use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.
the class TestNodeController method getPrimaryResourceFactory.
public IResourceFactory getPrimaryResourceFactory(IHyracksTaskContext ctx, PrimaryIndexInfo primaryIndexInfo, IStorageComponentProvider storageComponentProvider, Dataset dataset) throws AlgebricksException {
Dataverse dataverse = new Dataverse(dataset.getDataverseName(), NonTaggedDataFormat.class.getName(), MetadataUtil.PENDING_NO_OP);
Index index = primaryIndexInfo.getIndex();
CcApplicationContext appCtx = (CcApplicationContext) ExecutionTestUtil.integrationUtil.cc.getApplicationContext();
MetadataProvider mdProvider = new MetadataProvider(appCtx, dataverse, storageComponentProvider);
try {
return dataset.getResourceFactory(mdProvider, index, primaryIndexInfo.recordType, primaryIndexInfo.metaType, primaryIndexInfo.mergePolicyFactory, primaryIndexInfo.mergePolicyProperties);
} finally {
mdProvider.getLocks().unlock();
}
}
Aggregations