23
23
import org .opensearch .common .annotation .ExperimentalApi ;
24
24
import org .opensearch .core .action .ActionListener ;
25
25
26
+ import java .util .ArrayList ;
26
27
import java .util .List ;
27
28
import java .util .Map ;
28
29
import java .util .Optional ;
@@ -36,7 +37,7 @@ public class ViewService {
36
37
private final static Logger LOG = LogManager .getLogger (ViewService .class );
37
38
private final ClusterService clusterService ;
38
39
private final NodeClient client ;
39
- private LongSupplier timeProvider ;
40
+ private final LongSupplier timeProvider ;
40
41
41
42
public ViewService (final ClusterService clusterService , final NodeClient client , final LongSupplier timeProvider ) {
42
43
this .clusterService = clusterService ;
@@ -69,7 +70,6 @@ public void updateView(final CreateViewAction.Request request, final ActionListe
69
70
createOrUpdateView (Operation .UpdateView , updatedView , listener );
70
71
}
71
72
72
- @ SuppressWarnings ("deprecation" )
73
73
public void deleteView (final DeleteViewAction .Request request , final ActionListener <AcknowledgedResponse > listener ) {
74
74
getViewOrThrowException (request .getName ());
75
75
@@ -101,14 +101,12 @@ public void getView(final GetViewAction.Request request, final ActionListener<Ge
101
101
}
102
102
103
103
public void listViewNames (final ActionListener <ListViewNamesAction .Response > listener ) {
104
- final List <String > viewNames = Optional .ofNullable (clusterService )
104
+ final List <String > viewNames = new ArrayList <>( Optional .ofNullable (clusterService )
105
105
.map (ClusterService ::state )
106
106
.map (ClusterState ::metadata )
107
107
.map (Metadata ::views )
108
108
.map (Map ::keySet )
109
- .orElseThrow ()
110
- .stream ()
111
- .collect (Collectors .toList ());
109
+ .orElseThrow ());
112
110
113
111
listener .onResponse (new ListViewNamesAction .Response (viewNames ));
114
112
}
@@ -119,8 +117,7 @@ public void searchView(final SearchViewAction.Request request, final ActionListe
119
117
final String [] indices = view .getTargets ()
120
118
.stream ()
121
119
.map (View .Target ::getIndexPattern )
122
- .collect (Collectors .toList ())
123
- .toArray (new String [0 ]);
120
+ .toArray (String []::new );
124
121
request .indices (indices );
125
122
126
123
client .executeLocally (SearchAction .INSTANCE , request , listener );
@@ -130,7 +127,7 @@ View getViewOrThrowException(final String viewName) {
130
127
return Optional .ofNullable (clusterService )
131
128
.map (ClusterService ::state )
132
129
.map (ClusterState ::metadata )
133
- .map (m -> m . views () )
130
+ .map (Metadata :: views )
134
131
.map (views -> views .get (viewName ))
135
132
.orElseThrow (() -> new ResourceNotFoundException ("View [" + viewName + "] does not exist" ));
136
133
}
@@ -141,7 +138,7 @@ private enum Operation {
141
138
142
139
private final String name ;
143
140
144
- private Operation (final String name ) {
141
+ Operation (final String name ) {
145
142
this .name = name ;
146
143
}
147
144
}
0 commit comments