Skip to main content
summaryrefslogtreecommitdiffstats
blob: a30eec767fc98f2ffefe84e34a2e65efdfa2b151 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.server.admin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osee.framework.branch.management.TxCurrentsAndModTypesCommand;
import org.eclipse.osee.framework.core.enums.OseeCacheEnum;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.core.model.cache.AttributeTypeCache;
import org.eclipse.osee.framework.core.operation.CommandInterpreterLogger;
import org.eclipse.osee.framework.core.operation.IOperation;
import org.eclipse.osee.framework.core.operation.MutexSchedulingRule;
import org.eclipse.osee.framework.core.operation.OperationLogger;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.database.operation.ConsolidateArtifactVersionTxOperation;
import org.eclipse.osee.framework.database.operation.ConsolidateRelationsTxOperation;
import org.eclipse.osee.framework.database.operation.FindInvalidUTF8CharsOperation;
import org.eclipse.osee.framework.database.operation.ParseWindowsDirectoryListingOperation;
import org.eclipse.osee.framework.database.operation.PruneWorkspaceOperation;
import org.eclipse.osee.framework.database.operation.PurgeTransactionOperation;
import org.eclipse.osee.framework.database.operation.PurgeUnusedBackingDataAndTransactions;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.server.admin.internal.Activator;
import org.eclipse.osee.framework.server.admin.management.SchedulingCommand;
import org.eclipse.osee.framework.server.admin.management.ServerShutdownOperation;
import org.eclipse.osee.framework.server.admin.management.ServerStats;
import org.eclipse.osee.framework.server.admin.management.UpdateCachesOperation;
import org.eclipse.osee.framework.server.admin.management.UpdateServerVersionsOperation;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;

/**
 * @author Roberto E. Escobar
 */
public class ServerAdminCommandProvider implements CommandProvider {

   private final ISchedulingRule versionMutex = new MutexSchedulingRule();
   private final ISchedulingRule cacheMutex = new MutexSchedulingRule();
   private final ISchedulingRule shutdownMutex = new MutexSchedulingRule();

   public Job _server_status(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      return Operations.executeAsJob(new ServerStats(logger), false);
   }

   public void _server_process_requests(CommandInterpreter ci) throws OseeCoreException {
      String value = ci.nextArgument();
      Activator.getApplicationServerManager().setServletRequestsAllowed(new Boolean(value));
   }

   public Job _add_osee_version(CommandInterpreter ci) {
      return updateServerVersions(ci, true);
   }

   public Job _remove_osee_version(CommandInterpreter ci) {
      return updateServerVersions(ci, false);
   }

   private Job updateServerVersions(CommandInterpreter ci, boolean add) {
      String version = ci.nextArgument();
      OperationLogger logger = new CommandInterpreterLogger(ci);
      return Operations.executeAsJob(new UpdateServerVersionsOperation(logger, version, add), false, versionMutex);
   }

   public void _osee_version(CommandInterpreter ci) {
      ci.print("Osee Application Server: ");
      ci.println(Arrays.deepToString(Activator.getApplicationServerManager().getSupportedVersions()));
   }

   public Job _reload_cache(CommandInterpreter ci) {
      return updateCaches(ci, false);
   }

   public Job _clear_cache(CommandInterpreter ci) {
      return updateCaches(ci, false);
   }

   private Job updateCaches(CommandInterpreter ci, boolean reload) {
      Set<OseeCacheEnum> cacheIds = new HashSet<OseeCacheEnum>();

      for (String arg = ci.nextArgument(); Strings.isValid(arg); arg = ci.nextArgument()) {
         cacheIds.add(OseeCacheEnum.valueOf(arg));
      }

      OperationLogger logger = new CommandInterpreterLogger(ci);
      return Operations.executeAsJob(new UpdateCachesOperation(logger, cacheIds, reload), false, cacheMutex);
   }

   public Job _consolidate_artifact_versions(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      IOperation operation = new ConsolidateArtifactVersionTxOperation(Activator.getOseeDatabaseService(), logger);
      return Operations.executeAsJob(operation, false);
   }

   public Job _schedule(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      return Operations.executeAsJob(new SchedulingCommand(logger, ci), false);
   }

   public Job _tx_currents(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      boolean archived = Boolean.parseBoolean(ci.nextArgument());
      return Operations.executeAsJob(new TxCurrentsAndModTypesCommand(logger, archived), false);
   }

   public Job _purge_relation_type(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);

      //to be purged
      final Collection<String> relationTypes = new ArrayList<String>();

      boolean force = false;
      for (String arg = ci.nextArgument(); Strings.isValid(arg); arg = ci.nextArgument()) {
         if (arg.equals("-force")) {
            force = true;
         } else {
            relationTypes.add(arg);
         }
      }

      IOperation operation =
         new PurgeRelationType(Activator.getOseeDatabaseService(), Activator.getOseeCachingService(),
            Activator.getIdentityService(), logger, force, relationTypes.toArray(new String[relationTypes.size()]));

      return Operations.executeAsJob(operation, false);
   }

   public Job _tx_prune(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      return Operations.executeAsJob(new PurgeUnusedBackingDataAndTransactions(logger), false);
   }

   public Job _duplicate_attr(CommandInterpreter ci) throws OseeDataStoreException {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      AttributeTypeCache attTypeCache = Activator.getOseeCachingService().getAttributeTypeCache();
      return Operations.executeAsJob(
         new DuplicateAttributesOperation(logger, attTypeCache, Activator.getOseeDatabaseService()), false);
   }

   public Job _osee_shutdown(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      return Operations.executeAsJob(new ServerShutdownOperation(logger, ci), true, shutdownMutex);
   }

   public Job _parse_dir(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      String listingFile = ci.nextArgument();
      IOperation operation =
         new ParseWindowsDirectoryListingOperation(Activator.getOseeDatabaseService(),
            Activator.getOseeCachingService(), logger, listingFile);

      return Operations.executeAsJob(operation, false);
   }

   public Job _consolidate_relations(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);

      IOperation operation = new ConsolidateRelationsTxOperation(Activator.getOseeDatabaseService(), logger);

      return Operations.executeAsJob(operation, false);
   }

   public Job _find_invalid_utf8(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);

      IOperation operation =
         new FindInvalidUTF8CharsOperation(Activator.getOseeDatabaseService(), Activator.getOseeCachingService(),
            logger);

      return Operations.executeAsJob(operation, false);
   }

   public Job _prune_workspace(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);

      String preserveFilePattern = "";
      String workspacePathStr = "";
      String purgeFilePattern = "";

      //to be purged
      final ArrayList<String> args = new ArrayList<String>();

      for (String arg = ci.nextArgument(); Strings.isValid(arg); arg = ci.nextArgument()) {
         args.add(arg);
      }

      if (args.size() <= 1) {
         ci.print(getHelp());
      } else if (args.size() == 2) {
         workspacePathStr = args.get(0);
         purgeFilePattern = args.get(1);
      } else {
         preserveFilePattern = args.get(0);
         workspacePathStr = args.get(1);
         purgeFilePattern = args.get(2);
      }

      IOperation operation =
         new PruneWorkspaceOperation(Activator.getOseeDatabaseService(), Activator.getOseeCachingService(), logger,
            preserveFilePattern, workspacePathStr, purgeFilePattern);

      return Operations.executeAsJob(operation, false);
   }

   public Job _purge_transactions(CommandInterpreter ci) {
      OperationLogger logger = new CommandInterpreterLogger(ci);
      final List<Integer> transactions = new ArrayList<Integer>();

      for (String arg = ci.nextArgument(); Strings.isValid(arg); arg = ci.nextArgument()) {
         transactions.add(Integer.parseInt(arg));
      }

      IOperation operation = new PurgeTransactionOperation(Activator.getOseeDatabaseService(), logger, transactions);
      return Operations.executeAsJob(operation, false);
   }

   @Override
   public String getHelp() {
      StringBuilder sb = new StringBuilder();
      sb.append("\n---OSEE Server Admin Commands---\n");
      sb.append("        server_status - displays server status\n");
      sb.append("        server_process_requests [true | false]- command servlets to accept/reject requests\n");
      sb.append("        osee_version - displays the supported osee versions\n");
      sb.append("        add_osee_version [version string]- add the version string to the list of supported osee versions\n");
      sb.append("        remove_osee_version [version string]- removes the version string from the list of supported osee versions\n");
      sb.append("        finish_partial_archives - move txs addressing to osee_txs_archived for archived branches\n");
      sb.append("        consolidate_artifact_versions - migrate to 0.9.2 database schema\n");
      sb.append("        tx_currents [true | false] - detect and fix tx current and mod types inconsistencies on archive txs or txs\n");
      sb.append("        tx_prune - Purge artifact, attribute, and relation versions that are not addressed or nonexistent and purge empty transactions\n");
      sb.append("        duplicate_attr - detect and fix duplicate attributes\n");
      sb.append("        osee_shutdown [-oseeOnly] - immediately release the listening port then waits for all existing operations to finish. \n");
      sb.append("        schedule <delay seconds> <iterations> <command> - runs the command after the specified delay and repeat given number of times\n");
      sb.append("        purge_relation_type -force excute the operation, relationType1 ...\n");
      sb.append("        parse_dir - converts the given file into a formatted CSV file\n");
      sb.append("        purge_transactions <transaction ids> - ");
      sb.append("        prune_workspace [preserve_file_pattern] workspace_path purge_file_pattern - delete files that are found in workspace_path and whose filenames match purge_file_pattern.  Any filename that matches the optional preserve_file_pattern are not deleted\n");
      sb.append("        find_invalid_utf8 - finds invalid UTF8 chars in table osee_attribute\n");
      sb.append("        consolidate_relations - consolidate rows of relations\n");
      sb.append(String.format("        reload_cache %s? - reloads server caches\n",
         Arrays.deepToString(OseeCacheEnum.values()).replaceAll(",", " | ")));
      sb.append(String.format("        clear_cache %s? - decaches all objects from the specified caches\n",
         Arrays.deepToString(OseeCacheEnum.values()).replaceAll(",", " |")));
      return sb.toString();
   }
}

Back to the top