use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.
the class CmdLineTool method loadPlugins.
protected Set<Plugin> loadPlugins(String pluginPath, ChainingClassLoader chainingClassLoader) {
final File pluginDir = new File(pluginPath);
final Set<Plugin> plugins = new HashSet<>();
final PluginLoader pluginLoader = new PluginLoader(pluginDir, chainingClassLoader);
for (Plugin plugin : pluginLoader.loadPlugins()) {
final PluginMetaData metadata = plugin.metadata();
if (capabilities().containsAll(metadata.getRequiredCapabilities())) {
if (version.sameOrHigher(metadata.getRequiredVersion())) {
LOG.info("Loaded plugin: {}", plugin);
plugins.add(plugin);
} else {
LOG.error("Plugin \"" + metadata.getName() + "\" requires version " + metadata.getRequiredVersion() + " - not loading!");
}
} else {
LOG.debug("Skipping plugin \"{}\" because some capabilities are missing ({}).", metadata.getName(), Sets.difference(plugin.metadata().getRequiredCapabilities(), capabilities()));
}
}
return plugins;
}
use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.
the class SidecarResource method register.
@PUT
@Timed
@Path("/{sidecarId}")
@ApiOperation(value = "Create/update a Sidecar registration", notes = "This is a stateless method which upserts a Sidecar registration")
@ApiResponses(value = { @ApiResponse(code = 400, message = "The supplied request is not valid.") })
@RequiresPermissions(SidecarRestPermissions.SIDECARS_UPDATE)
@NoAuditEvent("this is only a ping from Sidecars, and would overflow the audit log")
public Response register(@ApiParam(name = "sidecarId", value = "The id this Sidecar is registering as.", required = true) @PathParam("sidecarId") @NotEmpty String sidecarId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull RegistrationRequest request, @HeaderParam(value = "X-Graylog-Sidecar-Version") @NotEmpty String sidecarVersion) {
final Sidecar newSidecar;
final Sidecar oldSidecar = sidecarService.findByNodeId(sidecarId);
List<ConfigurationAssignment> assignments = null;
if (oldSidecar != null) {
assignments = oldSidecar.assignments();
newSidecar = oldSidecar.toBuilder().nodeName(request.nodeName()).nodeDetails(request.nodeDetails()).sidecarVersion(sidecarVersion).lastSeen(DateTime.now(DateTimeZone.UTC)).build();
} else {
newSidecar = sidecarService.fromRequest(sidecarId, request, sidecarVersion);
}
sidecarService.save(newSidecar);
final CollectorActions collectorActions = actionService.findActionBySidecar(sidecarId, true);
List<CollectorAction> collectorAction = null;
if (collectorActions != null) {
collectorAction = collectorActions.action();
}
RegistrationResponse sidecarRegistrationResponse = RegistrationResponse.create(SidecarRegistrationConfiguration.create(this.sidecarConfiguration.sidecarUpdateInterval().toStandardDuration().getStandardSeconds(), this.sidecarConfiguration.sidecarSendStatus()), this.sidecarConfiguration.sidecarConfigurationOverride(), collectorAction, assignments);
return Response.accepted(sidecarRegistrationResponse).build();
}
use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.
the class ContentPackPersistenceService method filterMissingResourcesAndInsert.
public Optional<ContentPack> filterMissingResourcesAndInsert(final ContentPack pack) {
ContentPackV1 cpv1 = (ContentPackV1) pack;
final Set<String> allStreams = streamService.loadAll().stream().map(stream -> stream.getTitle()).collect(Collectors.toSet());
final Map<String, String> streamsInContentPack = new HashMap<>();
cpv1.entities().stream().filter(entity -> "stream".equals(entity.type().name()) && "1".equals(entity.type().version())).map(entity -> new Tuple2<String, JsonNode>(entity.id().id(), ((EntityV1) entity).data().findValue("title"))).forEach(tuple2 -> {
JsonNode title = tuple2.v2().findValue("@value");
streamsInContentPack.put(tuple2.v1(), title.textValue());
});
cpv1.entities().stream().filter(entity -> "dashboard".equals(entity.type().name()) && "2".equals(entity.type().version())).map(entity -> ((EntityV1) entity).data().findValue("search")).map(node -> node.findValue("queries")).map(node -> node.findValue("search_types")).forEach(node -> {
final ObjectNode parent = (ObjectNode) node.findParent("streams");
final ArrayNode streams = (ArrayNode) node.findValue("streams");
if (streams != null) {
final ArrayNode filtered = streams.deepCopy();
filtered.removeAll();
streams.forEach(stream -> {
final String sid = stream.textValue();
final String stitle = streamsInContentPack.get(sid);
if (allStreams.contains(stitle))
filtered.add(stream);
});
parent.replace("streams", filtered);
}
});
return this.insert(cpv1);
}
use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.
the class V20170607164210_MigrateReopenedIndicesToAliases method getReopenedIndices.
private Set<String> getReopenedIndices(final Collection<String> indices) {
final SearchVersion elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version."));
final JsonNode clusterStateJson = clusterState.getForIndices(indices);
final JsonNode indicesJson = clusterStateJson.path("metadata").path("indices");
final ImmutableSet.Builder<String> reopenedIndices = ImmutableSet.builder();
if (indicesJson.isMissingNode()) {
LOG.error("Retrieved cluster state is invalid (no metadata.indices key).");
LOG.debug("Received cluster state was: {}", clusterStateJson.toString());
return Collections.emptySet();
}
for (Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); it.hasNext(); ) {
final Map.Entry<String, JsonNode> entry = it.next();
final String indexName = entry.getKey();
final JsonNode value = entry.getValue();
final JsonNode indexSettings = value.path("settings");
if (indexSettings.isMissingNode()) {
LOG.error("Unable to retrieve index settings from metadata for index {} - skipping.", indexName);
LOG.debug("Index metadata was: {}", value.toString());
continue;
}
if (checkForReopened(indexSettings, elasticsearchVersion)) {
LOG.debug("Adding {} to list of indices to be migrated.", indexName);
reopenedIndices.add(indexName);
}
}
return reopenedIndices.build();
}
use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.
the class VersionCheckThread method doRun.
@Override
public void doRun() {
final Request request = new Request.Builder().addHeader(HttpHeaders.USER_AGENT, USER_AGENT).get().url(versionCheckUri.toString()).build();
try (final Response response = httpClient.newCall(request).execute()) {
if (response.isSuccessful()) {
final VersionCheckResponse versionCheckResponse = objectMapper.readValue(response.body().byteStream(), VersionCheckResponse.class);
final VersionResponse version = versionCheckResponse.version;
final com.github.zafarkhaja.semver.Version reportedVersion = com.github.zafarkhaja.semver.Version.forIntegers(version.major, version.minor, version.patch);
LOG.debug("Version check reports current version: " + versionCheckResponse);
if (reportedVersion.greaterThan(ServerVersion.VERSION.getVersion())) {
LOG.debug("Reported version is higher than ours ({}). Writing notification.", ServerVersion.VERSION);
Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.NORMAL).addType(Notification.Type.OUTDATED_VERSION).addDetail("current_version", versionCheckResponse.toString());
notificationService.publishIfFirst(notification);
} else {
LOG.debug("Reported version is not higher than ours ({}).", ServerVersion.VERSION);
notificationService.fixed(Notification.Type.OUTDATED_VERSION);
}
} else {
LOG.error("Version check unsuccessful (response code {}).", response.code());
}
} catch (IOException e) {
LOG.error("Couldn't perform version check", e);
}
}
Aggregations