daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.mule.extension.internal.sources;
  2.  
  3.  
  4.  
  5. import static org.mule.runtime.extension.api.annotation.param.MediaType.ANY;
  6.  
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9.  
  10. import org.apache.log4j.LogManager;
  11. import org.apache.log4j.Logger;
  12. import org.mule.extension.internal.BasicConnection;
  13.  
  14. import org.mule.runtime.api.exception.MuleException;
  15. import org.mule.runtime.extension.api.annotation.Alias;
  16. import org.mule.runtime.extension.api.annotation.param.Connection;
  17. import org.mule.runtime.extension.api.annotation.param.MediaType;
  18. import org.mule.runtime.extension.api.annotation.param.display.Placement;
  19. import org.mule.runtime.extension.api.annotation.source.EmitsResponse;
  20. import org.mule.runtime.extension.api.runtime.operation.Result;
  21. import org.mule.runtime.extension.api.runtime.source.PollContext;
  22. import org.mule.runtime.extension.api.runtime.source.PollingSource;
  23. import org.mule.runtime.extension.api.runtime.source.SourceCallback;
  24. import org.mule.runtime.extension.api.runtime.source.SourceCallbackContext;
  25.  
  26. import com.github.dockerjava.api.command.LogContainerCmd;
  27. import com.github.dockerjava.api.model.Frame;
  28.  
  29.  
  30. @Alias("usersource")
  31. @EmitsResponse
  32. @MediaType(value = ANY, strict = false)
  33. public class BasicSources extends PollingSource<InputStream, String> {
  34.  
  35.     static final Logger logger = LogManager.getLogger(BasicSources.class.getName());
  36.  
  37.     protected void doStart(final SourceCallback sourceCallback, final String containerName,
  38.            boolean showTimeStamp,
  39.             @Placement(order = 2) boolean standardOut,
  40.             @Placement(order = 3) boolean standardError,int showSince,
  41.             int tail, boolean followStream,@Connection BasicConnection con) throws MuleException{
  42.    
  43.  
  44.        
  45.         LogContainerCmd logContainerCmd =  con.dockerClient.logContainerCmd(containerName).withTimestamps(showTimeStamp).withStdOut(standardOut)
  46.                 .withStdErr(standardError).withSince(showSince).withFollowStream(followStream);
  47.                 logger.info("Getting container logs");
  48.                 if (tail != 0) {
  49.                     logger.debug("Container logs with tail : " + tail);
  50.                     logContainerCmd.withTail(tail);
  51.                 }
  52.                 SourceCallBack<Frame> logsCallback = logContainerCmd.exec(new SourceCallBack<Frame>(sourceCallback));
  53.                 try {
  54.                     logsCallback.awaitCompletion();
  55.                 } catch (InterruptedException e) {
  56.                     // TODO Auto-generated catch block
  57.                     e.printStackTrace();
  58.                 }
  59.                 try {
  60.                     logsCallback.close();
  61.                 } catch (IOException e) {
  62.                     // TODO Auto-generated catch block
  63.                     e.printStackTrace();
  64.                 }
  65.        
  66.        
  67.     }
  68.  
  69.     @Override
  70.     protected void doStop() {
  71.         // TODO Auto-generated method stub
  72.        
  73.     }
  74.  
  75.     @Override
  76.     public void poll(PollContext<InputStream, String> pollContext) {
  77.         // TODO Auto-generated method stub
  78.        
  79.     }
  80.  
  81.     @Override
  82.     public void onRejectedItem(Result<InputStream, String> result, SourceCallbackContext callbackContext) {
  83.         // TODO Auto-generated method stub
  84.        
  85.     }
  86.  
  87.     @Override
  88.     protected void doStart() throws MuleException {
  89.         // TODO Auto-generated method stub
  90.        
  91.     }
  92.  
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top