var component = new Component(); component = null; // delete this at next garbage collection
/** * Create an HTTPS restlet Server instance matching the given parameters. * * @param port * @param address * @param keystorePath * @param keystorePassword * @param keyPassword */ protected void setupServer(int port, String address, String keystorePath, String keystorePassword, String keyPassword) { Server server = new Server(Protocol.HTTPS,address,port,null); component.getServers().add(server); server.getContext().getParameters().add("keystorePath", keystorePath); server.getContext().getParameters().add("keystorePassword", keystorePassword); server.getContext().getParameters().add("keyPassword", keyPassword); }
@Override public synchronized int authenticate(Request request) { int retVal = super.authenticate(request); if(retVal == AUTHENTICATION_INVALID) { logger.warning("authentication failure "+request); // wait until at least LAG has passed from last failure // holding object lock the whole time, so no other checks // can happen in parallel long now = System.currentTimeMillis(); long sleepMs = (lastFailureTime+MIN_MS_BETWEEN_ATTEMPTS)-now; if(sleepMs>0) { try { Thread.sleep(sleepMs); } catch (InterruptedException e) { // ignore } } lastFailureTime = now + sleepMs; } return retVal; } }
component = new Component(); component.getClients().add(Protocol.FILE); component.getClients().add(Protocol.CLAP); Guard guard = new RateLimitGuard(null, ChallengeScheme.HTTP_DIGEST, "Authentication Required"); guard.getSecrets().put(authLogin, authPassword.toCharArray()); component.getDefaultHost().attach(guard); guard.setNext(new EngineApplication(engine)); component.start(); startupOut.println("engine listening at port "+port); startupOut.println("operator login set per " + component.stop();
@Override @Delete public Representation delete() { final String topicName = (String) getRequest().getAttributes().get("topicName"); if (_autoTopicWhitelistingManager != null) { _autoTopicWhitelistingManager.addIntoBlacklist(topicName); } if (!_helixMirrorMakerManager.isTopicExisted(topicName)) { getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation( String.format("Failed to delete not existed topic: %s", topicName)); } try { _helixMirrorMakerManager.deleteTopicInMirrorMaker(topicName); return new StringRepresentation( String.format("Successfully finished delete topic: %s", topicName)); } catch (Exception e) { getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); LOGGER.error("Failed to delete topic: {}, with exception: {}", topicName, e); return new StringRepresentation( String.format("Failed to delete topic: %s, with exception: %s", topicName, e)); } }
@Test public void testPost() { // Create topic Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL) .getTopicCreationRequestUrl("testTopic1", 16); Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully add new topic: {topic: testTopic1, partition: 16}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic1")); // Create existed topic request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL) .getTopicCreationRequestUrl("testTopic1", 16); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(response.getEntityAsText(), "Failed to add new topic: testTopic1, it is already existed!"); // Delete topic request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic1"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic1"); }
public ValidationRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _validationManager = (ValidationManager) getApplication().getContext() .getAttributes().get(ValidationManager.class.toString()); if (getApplication().getContext().getAttributes() .containsKey(SourceKafkaClusterValidationManager.class.toString())) { _srcKafkaValidationManager = (SourceKafkaClusterValidationManager) getApplication().getContext() .getAttributes().get(SourceKafkaClusterValidationManager.class.toString()); } else { _srcKafkaValidationManager = null; } }
public Request getTopicCreationRequestUrl(String topic, int numPartitions) { Request request = new Request(Method.POST, _baseUrl + "/topics/"); TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions); request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON); return request; }
public AdminRestletResource() { _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); }
public Request getTopicExternalViewRequestUrl(String topic) { String requestUrl = StringUtils.join(new String[] { _baseUrl, "/topics/", topic }); Request request = new Request(Method.GET, requestUrl); return request; }
public synchronized Restlet createRoot() { Router router = new Router(getContext()); router.attach("/",new Redirector(null,"/engine",Redirector.MODE_CLIENT_TEMPORARY)); router.attach("/engine",EngineResource.class) .setMatchingMode(Template.MODE_EQUALS); router.attach("/engine/",EngineResource.class) .setMatchingMode(Template.MODE_EQUALS); Directory alljobsdir = new Directory( getContext(), engine.getJobsDir().toURI().toString()); alljobsdir.setListingAllowed(true); router.attach("/engine/jobsdir",alljobsdir); router.attach("/engine/anypath/",anypath); jobdir.setModifiable(true); jobdir.setEditFilter(JobResource.EDIT_FILTER); router.attach("/engine/job/{job}/jobdir",jobdir); router.attach("/engine/job/{job}",JobResource.class); router.attach("/engine/job/{job}/report/{reportClass}",ReportGenResource.class); router.attach("/engine/job/{job}/beans",BeanBrowseResource.class); router.attach("/engine/job/{job}/beans/{beanPath}",BeanBrowseResource.class); router.attach("/engine/job/{job}/script",ScriptResource.class); Directory staticDir = new Directory(getContext(),resource); router.attach("/engine/static/",staticDir);
public void stop() { try { LOGGER.info("stopping broker topic observers"); for (String key : _kafkaBrokerTopicObserverMap.keySet()) { try { KafkaBrokerTopicObserver observer = _kafkaBrokerTopicObserverMap.get(key); observer.stop(); } catch (Exception e) { LOGGER.error("Failed to stop KafkaBrokerTopicObserver: {}!", key); } } LOGGER.info("stopping api component"); _component.stop(); LOGGER.info("stopping resource manager"); _helixMirrorMakerManager.stop(); } catch (final Exception e) { LOGGER.error("Caught exception", e); } }
public void runAnotherApp(Class<? extends Application> anotherAppClass) throws Exception { Application app2 = anotherAppClass.newInstance(); Stage anotherStage = new Stage(); app2.start(anotherStage); }
Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully add new topic: {topic: testTopic2, partition: 8}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic2")); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully expand topic: {topic: testTopic2, partition: 16}"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(response.getEntityAsText(), "Failed to expand topic, topic: testTopic22 is not existed!"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic2");
public TopicManagementRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); _autoTopicWhitelistingManager = (AutoTopicWhitelistingManager) getApplication().getContext() .getAttributes().get(AutoTopicWhitelistingManager.class.toString()); if (getApplication().getContext().getAttributes() .containsKey(KafkaBrokerTopicObserver.class.toString())) { _srcKafkaBrokerTopicObserver = (KafkaBrokerTopicObserver) getApplication().getContext() .getAttributes().get(KafkaBrokerTopicObserver.class.toString()); } else { _srcKafkaBrokerTopicObserver = null; } }
for (int i = 0; i < nComponents; i++) { AllComponents[i] = new Component(); AllComponents[i].Shifts = // Code here AllComponents[i].Couplings = // Code here }
public Request getTopicExpansionRequestUrl(String topic, int numPartitions) { Request request = new Request(Method.PUT, _baseUrl + "/topics/"); TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions); request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON); return request; } }
public Request getTopicDeleteRequestUrl(String topic) { String requestUrl = StringUtils.join(new String[] { _baseUrl, "/topics/", topic }); Request request = new Request(Method.DELETE, requestUrl); return request; }
for (int i = 0; i < nComponents; i++) { Component component = new Component(); component.Shifts = // Code here component.Couplings = // Code here AllComponents[i] = component; }
for (int i = 0; i < nComponents; i++) { AllComponents[i] = new Component(); }