Create snapshot of servers groups

@param expirationDays expiration days (must be between 1 and 10)
@param groupFilter    search servers criteria by group filter
@return OperationFuture wrapper for Server list
334453
public OperationFuture<List<Server>> createSnapshot(
            Integer expirationDays,
            GroupFilter groupFilter
    ) {
        return serverService().createSnapshot(
            expirationDays,
            getServerSearchCriteria(groupFilter)
        );
    }
829088
public OperationFuture<List<Server>> reset(Group... groups) {
        return serverService().reset(
            getServerSearchCriteria(groups)
        );
    }
40760
public ListDeploymentTargetsRequest withTargetFilters(java.util.Map<String, java.util.List<String>> targetFilters) {
        setTargetFilters(targetFilters);
        return this;
    }
1142128
@Test(groups = {SAMPLES})
    public void getDE1MonitoringStatsForLastHourGroupedByServers() {
        List<MonitoringStatsEntry> stats = statisticsService
            .monitoringStats()
            .forDataCenters(
                new DataCenterFilter()
                    .dataCenters(DE_FRANKFURT)
            )
            .forTime(new ServerMonitoringFilter()
                .last(Duration.ofHours(1))
                .type(MonitoringType.REALTIME)
                .interval(Duration.ofMinutes(10)))
            .groupByDataCenter();

        assertNotNull(stats);
    }
1047626
public OperationFuture<List<Server>> shutDown(Group... groups) {
        return serverService().shutDown(
            getServerSearchCriteria(groups)
        );
    }
1346665
public OperationFuture<List<Server>> pause(GroupFilter groupFilter) {
        return serverService().pause(
            getServerSearchCriteria(groupFilter)
        );
    }
1007233
static Predicate<DateValue> byMonthDayFilter(final int[] monthDays) {
		return new Predicate<DateValue>() {
			private static final long serialVersionUID = -1618039447294490037L;

			public boolean apply(DateValue date) {
				int nDays = TimeUtils.monthLength(date.year(), date.month());
				for (int i = monthDays.length - 1; i >= 0; i--) {
					int day = monthDays[i];
					if (day < 0) {
						day += nDays + 1;
					}
					if (day == date.day()) {
						return true;
					}
				}
				return false;
			}
		};
	}
1128204
public ServerFilter where(Predicate<ServerMetadata> filter) {
        checkNotNull(filter, "Filter must be not a null");

        predicate = predicate.and(filter);

        return this;
    }
1337281
public OperationFuture<List<Server>> stopMaintenance(Group... groups) {
        return serverService().stopMaintenance(
            getServerSearchCriteria(groups)
        );
    }
122323
public static Snapshot getSnapshot(ExecutorService service) {
        Preconditions.checkNotNull(service, "service");
        if (service instanceof ThreadPoolExecutor) {
            val tpe = (ThreadPoolExecutor) service;
            return new Snapshot(tpe.getQueue().size(), tpe.getActiveCount(), tpe.getPoolSize());
        } else if (service instanceof ForkJoinPool) {
            val fjp = (ForkJoinPool) service;
            return new Snapshot(fjp.getQueuedSubmissionCount(), fjp.getActiveThreadCount(), fjp.getPoolSize());
        } else {
            return null;
        }
    }
1000100
public ServerFilter groups(Group... groups) {
        allItemsNotNull(groups, "Groups");

        groupFilter = groupFilter.and(Filter.or(
            map(groups, Group::asFilter)
        ));

        return this;
    }
1355777
public OperationFuture<List<Server>> reset(GroupFilter groupFilter) {
        return serverService().reset(
            getServerSearchCriteria(groupFilter)
        );
    }
313227
public OperationFuture<List<Server>> archive(GroupFilter groupFilter) {
        return serverService().archive(
            getServerSearchCriteria(groupFilter)
        );
    }
770444
public static Filter populateFilter(final EntityManager entityManager, final Map<String, String> paramMap, final String filterName,
            final String tagPrefix, final String groupTagPrefix, final String categoryInternalPrefix, final String categoryExternalPrefix,
            final String localePrefix, final IFieldFilter fieldFilter) {
        // attempt to get the filter id from the url
        Integer filterId = null;
        if (paramMap.containsKey(filterName)) {
            final String filterQueryParam = paramMap.get(filterName);

            try {
                filterId = Integer.parseInt(filterQueryParam);
            } catch (final Exception ex) {
                // filter value was not an integer
                filterId = null;

                log.debug("The filter ID URL query parameter was not an integer. Got " + filterQueryParam + ". Probably a malformed URL.",
                        ex);
            }
        }

        Filter filter = null;

        /* First attempt to populate the filter from a filterID variable */
        if (filterId != null) {
            filter = entityManager.find(Filter.class, filterId);
        }

        /* If that fails, use the other URL params */
        if (filter == null) {
            filter = new Filter();

            for (final String key : paramMap.keySet()) {
                final boolean tagVar = tagPrefix != null && key.startsWith(tagPrefix);
                final boolean groupTagVar = groupTagPrefix != null && key.startsWith(groupTagPrefix);
                final boolean catIntVar = categoryInternalPrefix != null && key.startsWith(categoryInternalPrefix);
                final boolean catExtVar = categoryExternalPrefix != null && key.startsWith(categoryExternalPrefix);
                final boolean localeVar = localePrefix != null && key.matches("^" + localePrefix + "\\d*$");
                final String state = paramMap.get(key);

                // add the filter category states
                if (catIntVar || catExtVar) {
                    /*
                     * get the category and project id data from the variable name
                     */
                    final String catProjDetails = catIntVar ? key.replaceFirst(categoryInternalPrefix, "") : key.replaceFirst(
                            categoryExternalPrefix, "");
                    // split the category and project id out of the data
                    final String[] catProjID = catProjDetails.split("-");

                    /*
                     * some validity checks. make sure we have one or two strings after the split.
                     */
                    if (catProjID.length != 1 && catProjID.length != 2) continue;

                    // try to get the category and project ids
                    Integer catID = null;
                    Integer projID = null;
                    try {
                        catID = Integer.parseInt(catProjID[0]);

                        /*
                         * if the array has just one element, we have only specified the category. in this case the project is
                         * the common project
                         */
                        if (catProjID.length == 2) projID = Integer.parseInt(catProjID[1]);
                    } catch (final Exception ex) {
                        log.debug("Was expecting an integer. Got " + catProjID[0] + ". Probably a malformed URL.", ex);
                        continue;
                    }

                    // at this point we have found a url variable that
                    // contains a catgeory and project id

                    final Category category = entityManager.find(Category.class, catID);
                    final Project project = projID != null ? entityManager.find(Project.class, projID) : null;

                    Integer dbState;

                    if (catIntVar) {
                        if (state.equals(CommonFilterConstants.AND_LOGIC)) dbState = CommonFilterConstants.CATEGORY_INTERNAL_AND_STATE;
                        else dbState = CommonFilterConstants.CATEGORY_INTERNAL_OR_STATE;
                    } else {
                        if (state.equals(CommonFilterConstants.AND_LOGIC)) dbState = CommonFilterConstants.CATEGORY_EXTERNAL_AND_STATE;
                        else dbState = CommonFilterConstants.CATEGORY_EXTERNAL_OR_STATE;
                    }

                    final FilterCategory filterCategory = new FilterCategory();
                    filterCategory.setFilter(filter);
                    filterCategory.setProject(project);
                    filterCategory.setCategory(category);
                    filterCategory.setCategoryState(dbState);

                    filter.getFilterCategories().add(filterCategory);
                }

                // add the filter tag states
                else if (tagVar) {
                    try {
                        final Integer tagId = Integer.parseInt(key.replaceFirst(tagPrefix, ""));
                        final Integer intState = Integer.parseInt(state);

                        // get the Tag object that the tag id represents
                        final Tag tag = entityManager.getReference(Tag.class, tagId);

                        if (tag != null) {
                            final FilterTag filterTag = new FilterTag();
                            filterTag.setTag(tag);
                            filterTag.setTagState(intState);
                            filterTag.setFilter(filter);
                            filter.getFilterTags().add(filterTag);
                        }
                    } catch (final Exception ex) {
                        log.debug("Probably an invalid tag query parameter. Parameter: " + key + " Value: " + state, ex);
                    }
                } else if (groupTagVar) {
                    final Integer tagId = Integer.parseInt(key.replaceFirst(groupTagPrefix, ""));
                    // final Integer intState = Integer.parseInt(state);

                    // get the Tag object that the tag id represents
                    final Tag tag = entityManager.getReference(Tag.class, tagId);

                    if (tag != null) {
                        final FilterTag filterTag = new FilterTag();
                        filterTag.setTag(tag);
                        filterTag.setTagState(CommonFilterConstants.GROUP_TAG_STATE);
                        filterTag.setFilter(filter);
                        filter.getFilterTags().add(filterTag);
                    }
                } else if (localeVar) {
                    try {
                        final String localeName = state.replaceAll("\\d", "");
                        final Integer intState = Integer.parseInt(state.replaceAll("[^\\d]", ""));

                        final FilterLocale filterLocale = new FilterLocale();
                        filterLocale.setLocaleName(localeName);
                        filterLocale.setLocaleState(intState);
                        filterLocale.setFilter(filter);
                        filter.getFilterLocales().add(filterLocale);
                    } catch (final Exception ex) {
                        log.debug("Probably an invalid locale query parameter. Parameter: " + key + " Value: " + state, ex);
                    }
                }

                // add the filter field states
                else {
                    if (fieldFilter.hasFieldName(key)) {
                        final FilterField filterField = new FilterField();
                        filterField.setFilter(filter);
                        filterField.setField(key);
                        filterField.setValue(state);
                        filterField.setDescription(fieldFilter.getFieldDesc(key));
                        filter.getFilterFields().add(filterField);
                    }
                }

            }

        }

        return filter;
    }
378915
public OperationFuture<List<Server>> removeAutoscalePolicyOnServer(ServerFilter serverFilter) {
        return
            removeAutoscalePolicyOnServer(
                serverService
                    .findLazy(serverFilter)
                    .map(serverMetadata -> Server.refById(serverMetadata.getId()))
                    .collect(toList())
            );
    }
1179799
public OperationFuture<List<Server>> modifyPublicIp(ServerFilter filter, ModifyPublicIpConfig config) {
        return modifyPublicIp(Arrays.asList(getRefsFromFilter(filter)), config);
    }
227455
public OperationFuture<List<FirewallPolicy>> delete(FirewallPolicyFilter filter) {
        return delete(
            findLazy(filter)
                .map(metadata -> FirewallPolicy.refById(
                    metadata.getId(),
                    DataCenter.refById(metadata.getDataCenterId()))
                )
                .collect(toList())
        );
    }