Project

General

Profile

« Previous | Next » 

Revision 61677

fixed property for solr configuration files

View differences:

ZkUtils.java
5 5
import java.util.Map;
6 6
import java.util.Map.Entry;
7 7

  
8
import com.google.common.collect.Maps;
9
import eu.dnetlib.rmi.provision.IndexServiceException;
10 8
import org.apache.commons.io.IOUtils;
11 9
import org.apache.commons.logging.Log;
12 10
import org.apache.commons.logging.LogFactory;
......
19 17
import org.springframework.core.io.Resource;
20 18
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
21 19

  
20
import com.google.common.collect.Maps;
21

  
22
import eu.dnetlib.rmi.provision.IndexServiceException;
23

  
22 24
/**
23 25
 * The Class ZkUtils.
24 26
 */
......
53 55
	/**
54 56
	 * Upload zookeper config.
55 57
	 *
56
	 * @param zkClient  the zk client
57
	 * @param coreName  the core name
58
	 * @param fields    the fields
59
	 * @param params    the params
60
	 * @param overwrite the overwrite
58
	 * @param zkClient
59
	 *            the zk client
60
	 * @param coreName
61
	 *            the core name
62
	 * @param fields
63
	 *            the fields
64
	 * @param params
65
	 *            the params
66
	 * @param overwrite
67
	 *            the overwrite
61 68
	 */
62 69
	public void uploadZookeperConfig(final SolrZkClient zkClient,
63 70
			final String coreName,
......
72 79
		try {
73 80
			if (overwrite) {
74 81
				log.info("cleanup ZK configuration: " + coreName);
75
				for (String child : zkClient.getSolrZooKeeper().getChildren(basepath, false)) {
82
				for (final String child : zkClient.getSolrZooKeeper().getChildren(basepath, false)) {
76 83
					final String path = basepath + "/" + child;
77 84
					log.debug("cleanup ZK file: " + path);
78 85
					zkClient.delete(path, -1, true);
......
85 92
				uploadConfiguration(zkClient, basepath, buildConfiguration(coreName, fields, params));
86 93
			}
87 94
			log.info("upload ZK configuration complete");
88
		} catch (Exception e) {
95
		} catch (final Exception e) {
89 96
			log.error("unable to upload solr configuration", e);
90 97
		}
91 98
	}
......
93 100
	/**
94 101
	 * Builds the configuration.
95 102
	 *
96
	 * @param indexName the index name
97
	 * @param fields    the fields
98
	 * @param params    the params
103
	 * @param indexName
104
	 *            the index name
105
	 * @param fields
106
	 *            the fields
107
	 * @param params
108
	 *            the params
99 109
	 * @return the map
100
	 * @throws IndexServiceException the index service exception
110
	 * @throws IndexServiceException
111
	 *             the index service exception
101 112
	 */
102 113
	private Map<String, byte[]> buildConfiguration(final String indexName, final Document fields, final Map<String, String> params)
103 114
			throws IndexServiceException {
104 115

  
105
		Map<String, byte[]> res = Maps.newHashMap();
116
		final Map<String, byte[]> res = Maps.newHashMap();
106 117

  
107 118
		try {
108 119
			log.debug("adding schema.xml to the resource map");
......
110 121

  
111 122
			res.put("solrconfig.xml", configFactory.getConfig(params).getBytes());
112 123
			log.debug("adding solrconfig.xml to the resource map");
113
			PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
114
			Resource[] resources = resolver.getResources(getStaticConfigurationClasspath());
124
			final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
125
			final Resource[] resources = resolver.getResources(getStaticConfigurationClasspath());
115 126

  
116
			for (Resource r : resources) {
117
				InputStream is = r.getInputStream();
127
			for (final Resource r : resources) {
128
				final InputStream is = r.getInputStream();
118 129
				if ((r.getFilename() != null) && !r.getFilename().isEmpty()) {
119 130
					res.put(r.getFilename(), IOUtils.toByteArray(is));
120 131
					log.debug("adding " + r.getFilename() + " to the resource map");
......
122 133
				}
123 134
			}
124 135
			return res;
125
		} catch (Throwable e) {
136
		} catch (final Throwable e) {
126 137
			throw new IndexServiceException("failed to build configuration", e);
127 138
		}
128 139
	}
......
130 141
	/**
131 142
	 * Upload configuration.
132 143
	 *
133
	 * @param zkClient  the zk client
134
	 * @param basePath  the base path
135
	 * @param resources the resources
136
	 * @throws KeeperException      the keeper exception
137
	 * @throws InterruptedException the interrupted exception
138
	 * @throws IOException          Signals that an I/O exception has occurred.
144
	 * @param zkClient
145
	 *            the zk client
146
	 * @param basePath
147
	 *            the base path
148
	 * @param resources
149
	 *            the resources
150
	 * @throws KeeperException
151
	 *             the keeper exception
152
	 * @throws InterruptedException
153
	 *             the interrupted exception
154
	 * @throws IOException
155
	 *             Signals that an I/O exception has occurred.
139 156
	 */
140 157
	private void uploadConfiguration(final SolrZkClient zkClient, final String basePath, final Map<String, byte[]> resources) throws KeeperException,
141 158
			InterruptedException, IOException {
......
145 162
		}
146 163

  
147 164
		for (final Entry<String, byte[]> e : resources.entrySet()) {
148
			String path = basePath + "/" + e.getKey();
165
			final String path = basePath + "/" + e.getKey();
149 166
			log.debug("upload ZK configuration: " + path);
150 167
			zkClient.create(path, e.getValue(), CreateMode.PERSISTENT, true);
151 168
		}
......
163 180
	/**
164 181
	 * Sets the config factory.
165 182
	 *
166
	 * @param configFactory the new config factory
183
	 * @param configFactory
184
	 *            the new config factory
167 185
	 */
168 186
	@Required
169 187
	public void setConfigFactory(final IndexConfigFactory configFactory) {
......
182 200
	/**
183 201
	 * Sets the static configuration classpath.
184 202
	 *
185
	 * @param staticConfigurationClasspath the new static configuration classpath
203
	 * @param staticConfigurationClasspath
204
	 *            the new static configuration classpath
186 205
	 */
187 206
	@Required
188 207
	public void setStaticConfigurationClasspath(final String staticConfigurationClasspath) {

Also available in: Unified diff