001/* 002 * Copyright (c) 2018 Chris K Wensel <chris@wensel.net>. All Rights Reserved. 003 * 004 * Project and contact information: http://www.cascading.org/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021package cascading.local.tap.splunk; 022 023import java.io.OutputStream; 024import java.util.Properties; 025 026import cascading.flow.FlowProcess; 027import cascading.tuple.Fields; 028import cascading.tuple.TupleEntryCollector; 029import com.splunk.JobExportArgs; 030import com.splunk.Service; 031import com.splunk.ServiceArgs; 032 033/** 034 * Class SplunkSearchTap can return all the results from a given search query. 035 * <p> 036 * This Tap cannot be used to sink data into a Splunk cluster, see {@link SplunkIndexTap}. 037 */ 038public class SplunkSearchTap extends SplunkTap 039 { 040 private String search; 041 042 /** 043 * Instantiates a new SplunkSearchTap. 044 * 045 * @param scheme the scheme 046 * @param host the host 047 * @param port the port 048 * @param search the search 049 */ 050 public SplunkSearchTap( SplunkScheme scheme, String host, int port, String search ) 051 { 052 super( scheme, host, port ); 053 this.search = search; 054 } 055 056 /** 057 * Instantiates a new SplunkSearchTap. 058 * 059 * @param scheme the scheme 060 * @param serviceArgs the args 061 * @param search the search 062 */ 063 public SplunkSearchTap( SplunkScheme scheme, ServiceArgs serviceArgs, String search ) 064 { 065 super( scheme, serviceArgs ); 066 this.search = search; 067 } 068 069 /** 070 * Instantiates a new SplunkSearchTap. 071 * 072 * @param scheme the scheme 073 * @param serviceArgs the args 074 * @param exportArgs the export args 075 * @param search the search 076 */ 077 public SplunkSearchTap( SplunkScheme scheme, ServiceArgs serviceArgs, JobExportArgs exportArgs, String search ) 078 { 079 super( scheme, serviceArgs, exportArgs ); 080 this.search = search; 081 } 082 083 /** 084 * Instantiates a new SplunkSearchTap. 085 * 086 * @param scheme the scheme 087 * @param service the service 088 * @param search the search 089 */ 090 public SplunkSearchTap( SplunkScheme scheme, Service service, String search ) 091 { 092 super( scheme, service, null ); 093 this.search = search; 094 } 095 096 @Override 097 protected String getSplunkQuery() 098 { 099 return search; 100 } 101 102 @Override 103 protected String getSplunkPath() 104 { 105 return "/"; 106 } 107 108 @Override 109 protected String getSearch() 110 { 111 return String.format( "search %s", search ); 112 } 113 114 @Override 115 public Fields getSinkFields() 116 { 117 throw new UnsupportedOperationException( "unable to sink tuple streams via a SourceTap instance" ); 118 } 119 120 @Override 121 public final boolean isSink() 122 { 123 return false; 124 } 125 126 @Override 127 public boolean deleteResource( Properties conf ) 128 { 129 throw new UnsupportedOperationException( "unable to delete files via a SourceTap instance" ); 130 } 131 132 @Override 133 public void sinkConfInit( FlowProcess<? extends Properties> flowProcess, Properties conf ) 134 { 135 throw new UnsupportedOperationException( "unable to source tuple streams via a SourceTap instance" ); 136 } 137 138 @Override 139 public boolean prepareResourceForWrite( Properties conf ) 140 { 141 throw new UnsupportedOperationException( "unable to prepare resource for write via a SourceTap instance" ); 142 } 143 144 @Override 145 public boolean createResource( Properties conf ) 146 { 147 throw new UnsupportedOperationException( "unable to make dirs via a SourceTap instance" ); 148 } 149 150 @Override 151 public boolean commitResource( Properties conf ) 152 { 153 throw new UnsupportedOperationException( "unable to commit resource via a SourceTap instance" ); 154 } 155 156 @Override 157 public boolean rollbackResource( Properties conf ) 158 { 159 throw new UnsupportedOperationException( "unable to rollback resource via a SourceTap instance" ); 160 } 161 162 @Override 163 public boolean resourceExists( Properties conf ) 164 { 165 return true; 166 } 167 168 @Override 169 public long getModifiedTime( Properties conf ) 170 { 171 return Long.MAX_VALUE; 172 } 173 174 @Override 175 public TupleEntryCollector openForWrite( FlowProcess<? extends Properties> flowProcess, OutputStream output ) 176 { 177 throw new UnsupportedOperationException( "unable to open for write via a SourceTap instance" ); 178 } 179 }