-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding REST routes from JavaMonitor into wotaskd
- Loading branch information
Pascal Robert
committed
Aug 9, 2012
1 parent
5d910ba
commit 2120612
Showing
10 changed files
with
371 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...otaskd/Sources/com/webobjects/monitor/wotaskd/rest/controllers/JavaMonitorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.webobjects.monitor.wotaskd.rest.controllers; | ||
|
||
import com.webobjects.appserver.WOActionResults; | ||
import com.webobjects.appserver.WOApplication; | ||
import com.webobjects.appserver.WORequest; | ||
import com.webobjects.monitor._private.MSiteConfig; | ||
import com.webobjects.monitor.wotaskd.Application; | ||
|
||
import er.rest.routes.ERXDefaultRouteController; | ||
|
||
public class JavaMonitorController extends ERXDefaultRouteController { | ||
|
||
public JavaMonitorController(WORequest request) { | ||
super(request); | ||
} | ||
|
||
protected MSiteConfig siteConfig() { | ||
return application().siteConfig(); | ||
} | ||
|
||
public Application application() { | ||
return (Application )WOApplication.application(); | ||
} | ||
|
||
public WOActionResults createAction() throws Throwable { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
public WOActionResults destroyAction() throws Throwable { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
public WOActionResults indexAction() throws Throwable { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
public WOActionResults newAction() throws Throwable { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
public WOActionResults showAction() throws Throwable { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
public WOActionResults updateAction() throws Throwable { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
protected void checkPassword() throws SecurityException { | ||
String pw = context().request().stringFormValueForKey("pw"); | ||
if(!siteConfig().compareStringWithPassword(pw)) { | ||
throw new SecurityException("Invalid password"); | ||
} | ||
} | ||
|
||
} |
105 changes: 105 additions & 0 deletions
105
...taskd/Sources/com/webobjects/monitor/wotaskd/rest/controllers/MApplicationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.webobjects.monitor.wotaskd.rest.controllers; | ||
|
||
import com.webobjects.appserver.WOActionResults; | ||
import com.webobjects.appserver.WORequest; | ||
import com.webobjects.monitor._private.MApplication; | ||
import com.webobjects.monitor._private.MHost; | ||
import com.webobjects.monitor._private.MInstance; | ||
|
||
import er.extensions.eof.ERXKeyFilter; | ||
|
||
public class MApplicationController extends JavaMonitorController { | ||
|
||
public MApplicationController(WORequest request) { | ||
super(request); | ||
} | ||
|
||
public WOActionResults createAction() throws Throwable { | ||
checkPassword(); | ||
ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes(); | ||
MApplication application = create(filter); | ||
siteConfig().addApplication_W(application); | ||
return response(application, filter); | ||
} | ||
|
||
public WOActionResults destroyAction() throws Throwable { | ||
checkPassword(); | ||
MApplication application = (MApplication) routeObjectForKey("mApplication"); | ||
deleteApplication(application); | ||
return response(application, ERXKeyFilter.filterWithNone()); | ||
} | ||
|
||
public WOActionResults indexAction() throws Throwable { | ||
checkPassword(); | ||
return response(siteConfig().applicationArray(), ERXKeyFilter.filterWithAttributes()); | ||
} | ||
|
||
public WOActionResults showAction() throws Throwable { | ||
checkPassword(); | ||
MApplication application = (MApplication) routeObjectForKey("mApplication"); | ||
return response(application, ERXKeyFilter.filterWithAttributes()); | ||
} | ||
|
||
public WOActionResults updateAction() throws Throwable { | ||
checkPassword(); | ||
MApplication application = (MApplication) routeObjectForKey("mApplication"); | ||
update(application, ERXKeyFilter.filterWithAttributes()); | ||
return response(application, ERXKeyFilter.filterWithAttributes()); | ||
} | ||
|
||
public WOActionResults addInstanceAction() throws Throwable { | ||
checkPassword(); | ||
MApplication application = (MApplication) routeObjectForKey("name"); | ||
// Old code. The if statement replaces this code along with the addInstanceOnAllHostsAction() method. kib 20110622 | ||
// addInstance(application, (MHost)routeObjectForKey("host"), false); | ||
if (request().stringFormValueForKey("host") != null) { | ||
MHost mHost = siteConfig().hostWithName(request().stringFormValueForKey("host")); | ||
addInstance(application, mHost, false); | ||
} else | ||
addInstance(application, null, true); | ||
return response(application, ERXKeyFilter.filterWithNone()); | ||
} | ||
|
||
public WOActionResults deleteInstanceAction() throws Throwable { | ||
checkPassword(); | ||
MApplication application = (MApplication) routeObjectForKey("name"); | ||
deleteInstance(application, Integer.valueOf(request().stringFormValueForKey("id"))); | ||
return response(application, ERXKeyFilter.filterWithNone()); | ||
} | ||
|
||
public WOActionResults addInstanceOnAllHostsAction() throws Throwable { | ||
checkPassword(); | ||
MApplication application = (MApplication) routeObjectForKey("name"); | ||
addInstance(application, null, true); | ||
return response(application, ERXKeyFilter.filterWithNone()); | ||
} | ||
|
||
private void addInstance(MApplication application, MHost host, boolean addToAllHosts) { | ||
try { | ||
if (addToAllHosts) { | ||
for (MHost aHost : siteConfig().hostArray()) { | ||
siteConfig().addInstances_M(aHost, application, 1); | ||
} | ||
} else { | ||
siteConfig().addInstances_M(host, application, 1); | ||
} | ||
} finally { | ||
} | ||
} | ||
|
||
private void deleteInstance(MApplication application, Integer instanceId) { | ||
final MInstance instance = application.instanceWithID(instanceId); | ||
try { | ||
siteConfig().removeInstance_M(instance); | ||
} finally { | ||
} | ||
} | ||
|
||
private void deleteApplication(MApplication application) { | ||
try { | ||
siteConfig().removeApplication_M(application); | ||
} finally { | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...ions/wotaskd/Sources/com/webobjects/monitor/wotaskd/rest/controllers/MHostController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.webobjects.monitor.wotaskd.rest.controllers; | ||
|
||
import com.webobjects.appserver.WOActionResults; | ||
import com.webobjects.appserver.WORequest; | ||
import com.webobjects.monitor._private.MHost; | ||
|
||
import er.extensions.eof.ERXKeyFilter; | ||
|
||
public class MHostController extends JavaMonitorController { | ||
|
||
public MHostController(WORequest request) { | ||
super(request); | ||
} | ||
|
||
public WOActionResults createAction() throws Throwable { | ||
checkPassword(); | ||
MHost host = create(ERXKeyFilter.filterWithAttributes()); | ||
siteConfig().addHost_M(host); | ||
return response(host, ERXKeyFilter.filterWithAttributes()); | ||
} | ||
|
||
public WOActionResults indexAction() throws Throwable { | ||
checkPassword(); | ||
return response(siteConfig().hostArray(), ERXKeyFilter.filterWithAttributes()); | ||
} | ||
|
||
public WOActionResults showAction() throws Throwable { | ||
checkPassword(); | ||
MHost host = siteConfig().hostWithName((String) routeObjectForKey("mHost")); | ||
return response(host, ERXKeyFilter.filterWithAttributes()); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...otaskd/Sources/com/webobjects/monitor/wotaskd/rest/controllers/MSiteConfigController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.webobjects.monitor.wotaskd.rest.controllers; | ||
|
||
import com.webobjects.appserver.WOActionResults; | ||
import com.webobjects.appserver.WORequest; | ||
import com.webobjects.foundation.NSMutableDictionary; | ||
import com.webobjects.monitor._private.MSiteConfig; | ||
|
||
import er.extensions.eof.ERXKeyFilter; | ||
import er.extensions.foundation.ERXStringUtilities; | ||
|
||
public class MSiteConfigController extends JavaMonitorController { | ||
|
||
public MSiteConfigController(WORequest request) { | ||
super(request); | ||
} | ||
|
||
public WOActionResults updateAction() throws Throwable { | ||
checkPassword(); | ||
if (siteConfig().hostArray().count() == 0) { | ||
throw new IllegalStateException("You cannot update the SiteConfig before adding a host."); | ||
} | ||
MSiteConfig siteConfig = (MSiteConfig) object(ERXKeyFilter.filterWithAttributes()); | ||
update(siteConfig, ERXKeyFilter.filterWithAttributes()); | ||
pushValues(siteConfig); | ||
return response(siteConfig, ERXKeyFilter.filterWithAttributes()); | ||
} | ||
|
||
private void pushValues(MSiteConfig newSiteConfig) { | ||
// Grab the new and current hashed passwords. Any new password coming in has already been hashed | ||
// and if we don't have a new password we need the old hashed one to put back into the SiteConfig | ||
// once we've blatted the values with the new incoming values. | ||
String newHashedPassword = newSiteConfig.password(); | ||
String currentHashedPassword = siteConfig().password(); | ||
|
||
if (!ERXStringUtilities.stringIsNullOrEmpty(newHashedPassword)) { | ||
// This is needed to populate the passwordDictionary in the request posted to wotaskd. | ||
siteConfig()._setOldPassword(); | ||
} | ||
|
||
// Now we've cached the new value remove it from the newSiteConfig. | ||
newSiteConfig.values().removeObjectForKey("password"); | ||
|
||
// Build a dictionary of new values. Because we might only be updating a few values (and not the whole | ||
// SiteConfig) we'll start with all the current values, less the password which we've already cached. | ||
NSMutableDictionary newValues = siteConfig().values(); | ||
newValues.removeObjectForKey("password"); | ||
|
||
// Overwrite and/or add the new incoming values. | ||
newValues.addEntriesFromDictionary(newSiteConfig.values()); | ||
|
||
// Push the complete set of new values into the current SiteConfig object. | ||
siteConfig().updateValues(newValues); | ||
|
||
// OK, let's check what needs to be done with the password. If we've got a new one set that, otherwise | ||
// if we've got an old one put that back into the SiteConfig. | ||
if (!ERXStringUtilities.stringIsNullOrEmpty(newHashedPassword)) { | ||
siteConfig().values().takeValueForKey(newHashedPassword, "password"); | ||
} else if (!ERXStringUtilities.stringIsNullOrEmpty(currentHashedPassword)) { | ||
siteConfig().values().takeValueForKey(currentHashedPassword, "password"); | ||
} | ||
|
||
if (!ERXStringUtilities.stringIsNullOrEmpty(newHashedPassword)) { | ||
siteConfig()._resetOldPassword(); | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...otaskd/Sources/com/webobjects/monitor/wotaskd/rest/delegates/JavaMonitorRestDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.webobjects.monitor.wotaskd.rest.delegates; | ||
|
||
import com.webobjects.appserver.WOApplication; | ||
import com.webobjects.monitor._private.MSiteConfig; | ||
import com.webobjects.monitor.wotaskd.Application; | ||
|
||
import er.rest.ERXAbstractRestDelegate; | ||
|
||
public abstract class JavaMonitorRestDelegate extends ERXAbstractRestDelegate { | ||
|
||
protected MSiteConfig siteConfig() { | ||
return application().siteConfig(); | ||
} | ||
|
||
public Application application() { | ||
return (Application )WOApplication.application(); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...taskd/Sources/com/webobjects/monitor/wotaskd/rest/delegates/MApplicationRestDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.webobjects.monitor.wotaskd.rest.delegates; | ||
|
||
import com.webobjects.eocontrol.EOClassDescription; | ||
import com.webobjects.foundation.NSArray; | ||
import com.webobjects.monitor._private.MApplication; | ||
|
||
import er.extensions.eof.ERXQ; | ||
import er.rest.ERXRestContext; | ||
|
||
public class MApplicationRestDelegate extends JavaMonitorRestDelegate { | ||
public Object primaryKeyForObject(Object obj, ERXRestContext context) { | ||
NSArray<MApplication> objects = ERXQ.filtered(siteConfig().applicationArray(), ERXQ.is("name", obj)); | ||
return objects.size() == 0 ? null : objects.objectAtIndex(0); | ||
} | ||
|
||
public Object createObjectOfEntityWithID(EOClassDescription entity, Object id, ERXRestContext context) { | ||
return new MApplication((String)id, siteConfig()); | ||
} | ||
|
||
public Object objectOfEntityWithID(EOClassDescription entity, Object id, ERXRestContext context) { | ||
return (siteConfig().applicationWithName((String)id)); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...ions/wotaskd/Sources/com/webobjects/monitor/wotaskd/rest/delegates/MHostRestDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.webobjects.monitor.wotaskd.rest.delegates; | ||
|
||
import com.webobjects.eocontrol.EOClassDescription; | ||
import com.webobjects.foundation.NSArray; | ||
import com.webobjects.monitor._private.MHost; | ||
|
||
import er.extensions.eof.ERXQ; | ||
import er.rest.ERXRestContext; | ||
|
||
public class MHostRestDelegate extends JavaMonitorRestDelegate { | ||
public Object createObjectOfEntityWithID(EOClassDescription entity, Object id, ERXRestContext context) { | ||
return new MHost(siteConfig(), (String)id, MHost.MAC_HOST_TYPE); | ||
} | ||
|
||
public Object objectOfEntityWithID(EOClassDescription entity, Object id, ERXRestContext context) { | ||
return (siteConfig().hostWithName((String)id)); | ||
} | ||
|
||
public Object primaryKeyForObject(Object obj, ERXRestContext context) { | ||
NSArray<MHost> objects = ERXQ.filtered(siteConfig().hostArray(), ERXQ.is("name", obj)); | ||
return objects.size() == 0 ? null : objects.objectAtIndex(0); | ||
} | ||
|
||
} |
Oops, something went wrong.